xi0325 发表于 2017-3-23 17:22:15

有谁调过显示屏转换IC??

我现在在rk3288上边调试一款mipi转edp的转换ic,有谁调试过显示屏转换IC的,能否传授下经验~_~~_~

loading 发表于 2017-3-23 18:49:14

方便把你代码贴上来吗?

xi0325 发表于 2017-3-23 18:57:13

loading 发表于 2017-3-23 18:49
方便把你代码贴上来吗?


/*******************************************************

// I2C_Adr = 0x52;// bit0 是读写标志位;如果是Linux系统,IIC address 的 bit7作为读写标志位,则I2C_Adr 应该是 0x29;


// IIC速率不要超过100KHz
// 刷寄存器之前,先Reset LT8911/B ,用GPIO 先拉低LT8911/B的复位脚 150ms左右,再拉高,保持150ms

LT8911/LT8911B mipi输入格式、要求:
1,non-burst mode(continue mode)
2,Video mode
3,sync event
4,MIPI DSI

*********************************************************/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fb.h>
#include <linux/fs.h>
#include <linux/rk_fb.h>
#include <linux/seq_file.h>
#include <linux/time.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/debugfs.h>
#include <linux/of_gpio.h>
#include <linux/rk_screen.h>
#include "mipi_dsi.h"
#include "anx6345.h"
#include "lt8911.h"
#include "dpcd_edid.h"

#if defined(CONFIG_HAS_EARLYSUSPEND)
#include <linux/earlysuspend.h>
#endif



//#define _Test_Pattern_
#defineMODULE_NAME             "LT8911"
#defineMODULE_I2C_ADDR          (0x52>>1)//(0xE0>>1)

static struct i2c_client *lt8911_client = NULL;
static struct lt8911 *lt8911;

//#define _1080P_eDP_Panel_
#define _1366x768_eDP_Panel_
//#define _1280x800_eDP_Panel_

#define _MIPI_Lane_        4 // MIPI Lane 1,2,4

//******************************************************//

//#ifdef _1080P_eDP_Panel_

// 根据前端MIPI信号的Timing,修改以下参数:
//static int MIPI_Timing[] =
        //H_act V_act        H_total V_total H_BP        H_sync        V_sync        V_BP
//        {1920,        1080,        2200,        1125,        148,        44,         5,        36};// 1080PVesa Timing
//        {1920,        1080,        2080,        1111,        80,        32,        5,        16};

//#define _2_Lane_

// #define _8_Bit_ColorDepth_ // eDP panel Color Depth,16.7M color
//#define _6_Bit_ColorDepth_ // eDP panel Color Depth,262K color

//#endif

//******************************************************//

//#ifdef _1280x800_eDP_Panel_

// 根据前端MIPI信号的Timing,修改以下参数:
//static int MIPI_Timing[] =
        //H_act V_act        H_total V_total H_BP        H_sync        V_sync        V_BP
//        {1280,        800,        1440,        823,        80,        32,         6,        14};// _1280x800 Vesa Timing

//#define _1_Lane_

//#define _6_Bit_ColorDepth_ // eDP panel Color Depth,262K color

//#endif

//******************************************************//

#ifdef _1366x768_eDP_Panel_

// 根据前端MIPI信号的Timing,修改以下参数:
static int MIPI_Timing[] =
        //H_act V_act        H_total V_total H_BP        H_sync        V_sync        V_BP
        {1368,        768,        1592,        800,        104,        48,        6,        23};// 1366x768 VESA Timing

#define _1_Lane_

#define _6_Bit_ColorDepth_ // eDP panel Color Depth,262K color

#endif

//******************************************************//

enum
{
H_act = 0,
V_act,
H_tol,
V_tol,
H_bp,
H_sync,
V_sync,
V_bp
};

u8 swing_req=0x00;

#define Swing_Level_Close        0x00

#define Swing_Level_0_H        0x00
#define Swing_Level_0_L        0xa0

#define Swing_Level_1_H        0x00
#define Swing_Level_1_L        0xf0

#define Swing_Level_2_H        0x01
#define Swing_Level_2_L        0x40

#define Swing_Level_3_H        0x02
#define Swing_Level_3_L        0xb4

static u8 DPCD0000H;
static u8 DPCD0001H;
static u8 DPCD0002H;
static u8 DPCD0003H;
static u8 DPCD0004H;
static u8 DPCD0005H;
static u8 DPCD0006H;
static u8 DPCD0007H;
static u8 DPCD0008H;
static u8 DPCD0009H;
static u8 DPCD000aH;
static u8 DPCD000bH;
static u8 DPCD0200H;
static u8 DPCD0201H;
u8 DPCD0202H;
static u8 DPCD0203H;
static u8 DPCD0204H;
static u8 DPCD0205H;
u8 DPCD0206H;

static int i2c_master_reg8_send(const struct i2c_client *client,
                const char reg, const char *buf, int count, int scl_rate)
{
      struct i2c_adapter *adap=client->adapter;
      struct i2c_msg msg;
      int ret;
      char *tx_buf = (char *)kmalloc(count + 1, GFP_KERNEL);
      if(!tx_buf)
                return -ENOMEM;
      tx_buf = reg;
      memcpy(tx_buf+1, buf, count);

      msg.addr = client->addr;
      msg.flags = client->flags;
      msg.len = count + 1;
      msg.buf = (char *)tx_buf;
      msg.scl_rate = scl_rate;

      ret = i2c_transfer(adap, &msg, 1);
      kfree(tx_buf);
      return (ret == 1) ? count : ret;

}

static int i2c_master_reg8_recv(const struct i2c_client *client,
                const char reg, char *buf, int count, int scl_rate)
{
      struct i2c_adapter *adap=client->adapter;
      struct i2c_msg msgs;
      int ret;
      char reg_buf = reg;

      msgs.addr = client->addr;
      msgs.flags = client->flags;
      msgs.len = 1;
      msgs.buf = &reg_buf;
      msgs.scl_rate = scl_rate;

      msgs.addr = client->addr;
      msgs.flags = client->flags | I2C_M_RD;
      msgs.len = count;
      msgs.buf = (char *)buf;
      msgs.scl_rate = scl_rate;

      ret = i2c_transfer(adap, msgs, 2);

      return (ret == 2)? count : ret;
}

static u8 HDMI_ReadI2C_Byte(unsigned char reg_addr)
{
    u8 dummy;
    unsigned char addr;
        unsigned char val;
    addr = reg_addr;   
    //dummy = i2c_smbus_read_byte_data(lt8911_client, addr);
        //printk("HDMI_ReadI2C_Byte dummy=%d\n",dummy);
        dummy = i2c_master_reg8_recv(lt8911_client, addr, &val, 1, LT8911_SCL_RATE);
        //dummy = i2c_master_recv(addr, &val, 1);
    if (dummy < 0)
      return -1;
    return dummy & 0x000000ff;
}

/***********
HDMI_WriteI2C_Byte
lt8911_smbus_write_byte(unsigned char reg_addr, unsigned char data)
***********/
static int HDMI_WriteI2C_Byte(unsigned char reg_addr, unsigned char data)
{
    s32 dummy;
    unsigned char addr;
    //unsigned char *tmp;
    addr = reg_addr;      
    //tmp = &data;
    //dummy = i2c_smbus_write_byte_data(lt8911_client, addr, *tmp);
        //printk("HDMI_WriteI2C_Byte dummy=%d addr=0x%x tmp=0x%x\n",dummy,addr,tmp);
        dummy = i2c_master_reg8_send(lt8911_client, addr, &data, 1, LT8911_SCL_RATE);
        //dummy = i2c_master_send(addr, &data, 1);
    if (dummy < 0)
      return -1;
    return 0;
}

void DpcdWrite(u32 Address, u8 Data)
{
        u8 AddressH = 0x0f & (Address>>16);
        u8 AddressM = 0xff & (Address>>8);
        u8 AddressL = 0xff &Address    ;

        HDMI_WriteI2C_Byte(0xff,0x80);
        HDMI_WriteI2C_Byte(0x36,0x00);
        HDMI_WriteI2C_Byte(0x30,0x0e);// 0x11
        HDMI_WriteI2C_Byte(0x33,AddressL);
        HDMI_WriteI2C_Byte(0x34,AddressM);
        HDMI_WriteI2C_Byte(0x35,AddressH);
        HDMI_WriteI2C_Byte(0x37,Data);       
        HDMI_WriteI2C_Byte(0x36,0x20);
}

u8 DpcdRead(u32 Address)
{
        u8 read_cnt=0x03;
        u8 DpcdValue = 0x00;
        u8 AddressH = 0x0f & (Address>>16);
        u8 AddressM = 0xff & (Address>>8);
        u8 AddressL = 0xff &Address    ;
       
        HDMI_WriteI2C_Byte(0xff,0x80);
        HDMI_WriteI2C_Byte(0x36,0x00);
        HDMI_WriteI2C_Byte(0x30,0x8e);// 0x91
        HDMI_WriteI2C_Byte(0x33,AddressL);
        HDMI_WriteI2C_Byte(0x34,AddressM);
        HDMI_WriteI2C_Byte(0x35,AddressH);
        HDMI_WriteI2C_Byte(0x36,0x20);

        mdelay(2); //必要的

        if(HDMI_ReadI2C_Byte(0x39)==0x01)
                {
                DpcdValue = HDMI_ReadI2C_Byte(0x38);
                }
        else
                {
                while((HDMI_ReadI2C_Byte(0x39)!=0x01)&&(read_cnt>0))
                        {
                        HDMI_WriteI2C_Byte(0x36,0x00);
                        HDMI_WriteI2C_Byte(0x36,0x20);
                        read_cnt--;
                        mdelay(2);
                        }

                if(HDMI_ReadI2C_Byte(0x39)==0x01)
                        {
                        DpcdValue = HDMI_ReadI2C_Byte(0x38);
                        }
                }
        return DpcdValue;
}


void adj_swing(void)
{
        swing_req=DPCD0206H&0x0f;      //lane 0
        HDMI_WriteI2C_Byte(0xff,0x81);
        switch(swing_req)
                {
                case 0x00:        
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
                        DpcdWrite(0x0103,0x00);
                        break;
                       
                case 0x01:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_1_L);
                        DpcdWrite(0x0103,0x01);
                        break;

                case 0x02:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_2_L);
                        DpcdWrite(0x0103,0x02);
                        break;
                       
                case 0x03:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_3_L);
                        DpcdWrite(0x0103,0x07);
                        break;
                       
                case 0x04:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
                        DpcdWrite(0x0103,0x08);
                        break;
                       
                case 0x05:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_1_L);
                        DpcdWrite(0x0103,0x09);
                        break;
                       
                case 0x06:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_2_L);
                        DpcdWrite(0x0103,0x0a);
                        break;
                       
                case 0x07:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_3_L);
                        DpcdWrite(0x0103,0x0f);
                        break;
                       
                case 0x08:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
                        DpcdWrite(0x0103,0x10);
                        break;
                       
                case 0x09:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_1_L);
                        DpcdWrite(0x0103,0x11);
                        break;
                       
                case 0x0a:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_2_L);
                        DpcdWrite(0x0103,0x12);
                        break;
                       
                case 0x0b:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_3_L);
                        DpcdWrite(0x0103,0x17);
                        break;
                       
                case 0x0c:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
                        DpcdWrite(0x0103,0x38);
                        break;
                       
                case 0x0d:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_1_L);
                        DpcdWrite(0x0103,0x39);
                        break;
                       
                case 0x0e:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_2_L);
                        DpcdWrite(0x0103,0x3a);
                        break;
                       
                case 0x0f:
                        HDMI_WriteI2C_Byte(0x18,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x19,Swing_Level_3_L);
                        DpcdWrite(0x0103,0x3f);
                        break;
                       
                default:   break;
          }

        #ifdef _2_Lane_

                swing_req=DPCD0206H&0xf0;      //lane 1
                HDMI_WriteI2C_Byte(0xff,0x81);
                switch(swing_req)
                {
                case 0x00:        
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_0_L);
                        DpcdWrite(0x0104,0x00);
                        break;
                       
                case 0x10:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_1_L);
                        DpcdWrite(0x0104,0x01);
                        break;
                       
                case 0x20:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_2_L);
                        DpcdWrite(0x0104,0x02);
                        break;
                       
                case 0x30:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_3_L);
                        DpcdWrite(0x0104,0x07);
                        break;
                       
                case 0x40:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_0_L);
                        DpcdWrite(0x0104,0x08);
                        break;
                       
                case 0x50:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_1_L);
                        DpcdWrite(0x0104,0x09);
                        break;
                       
                case 0x60:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_2_L);
                        DpcdWrite(0x0104,0x0a);
                        break;
                       
                case 0x70:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_3_L);
                        DpcdWrite(0x0104,0x0f);
                        break;
                       
                case 0x80:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_0_L);
                        DpcdWrite(0x0104,0x10);
                        break;
                       
                case 0x90:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_1_L);
                        DpcdWrite(0x0104,0x11);
                        break;
                       
                case 0xa0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_2_L);
                        DpcdWrite(0x0104,0x12);
                        break;
                               
                case 0xb0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_3_L);
                        DpcdWrite(0x0104,0x17);
                        break;
                       
                case 0xc0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_0_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_0_L);
                        DpcdWrite(0x0104,0x38);
                        break;
                       
                case 0xd0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_1_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_1_L);
                        DpcdWrite(0x0104,0x39);
                        break;
                       
                case 0xe0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_2_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_2_L);
                        DpcdWrite(0x0104,0x3a);
                        break;
                       
                case 0xf0:
                        HDMI_WriteI2C_Byte(0x1a,Swing_Level_3_H);   
                        HDMI_WriteI2C_Byte(0x1b,Swing_Level_3_L);
                        DpcdWrite(0x0104,0x3f);break;
                default:   break;
          }
        #endif
       
}


void LT8911_AUX_Training(void)
{
        u8 swing_adj_cnt=0x00;
        DPCD0202H=0x00;
        DPCD0000H=DpcdRead(0x0000);
        DPCD0200H=DpcdRead(0x0200);
        DPCD0201H=DpcdRead(0x0201);
        DPCD0202H=DpcdRead(0x0202);
        DPCD0203H=DpcdRead(0x0203);
        DPCD0204H=DpcdRead(0x0204);
        DPCD0205H=DpcdRead(0x0205);
        DPCD0000H=DpcdRead(0x0000);
        DPCD0001H=DpcdRead(0x0001);
        DPCD0002H=DpcdRead(0x0002);
        DPCD0003H=DpcdRead(0x0003);
        DPCD0004H=DpcdRead(0x0004);
        DPCD0005H=DpcdRead(0x0005);
        DPCD0006H=DpcdRead(0x0006);
        DPCD0007H=DpcdRead(0x0007);
        DPCD0008H=DpcdRead(0x0008);
        DPCD0009H=DpcdRead(0x0009);
        DPCD000aH=DpcdRead(0x000a);
        DPCD000bH=DpcdRead(0x000b);
       
        HDMI_WriteI2C_Byte(0xff,0x80);//register bank               
        HDMI_WriteI2C_Byte(0x62,0x3f); //Reset dp video

#ifdef _2_Lane_
        HDMI_WriteI2C_Byte(0x03,0x42); //41-1lane,42-2lane,44-4lane
#endif

#ifdef _1_Lane_
        HDMI_WriteI2C_Byte(0x03,0x41); //41-1lane,42-2lane,44-4lane
#endif

        HDMI_WriteI2C_Byte(0x04,0x14);        

        HDMI_WriteI2C_Byte(0xff,0x84);//register bank
        HDMI_WriteI2C_Byte(0x14,0x01);       
        HDMI_WriteI2C_Byte(0x14,0x81);
        HDMI_WriteI2C_Byte(0x14,0x82);
       
        DpcdWrite(0x0600,0x01);
       
        if(DpcdRead(0x0600)!=0x01)
                {
                DpcdWrite(0x0600,0x01);
                }
       
        DpcdWrite(0x0100,0x0a);

#ifdef _2_Lane_
        DpcdWrite(0x0101,0x82); // 2 lane
#endif

#ifdef _1_Lane_
        DpcdWrite(0x0101,0x81); // 1 lane
#endif

        DpcdWrite(0x010a,0x00);
        DpcdWrite(0x0107,0x00);
        DpcdWrite(0x0108,0x01);

        if(DpcdRead(0x0100)!=0x0a)
                {
                DpcdWrite(0x0100,0x0a);
                }

#ifdef _2_Lane_       
        if(DpcdRead(0x0101)!=0x82) // 2 Lane
                {
                DpcdWrite(0x0101,0x82);
                }
#endif

#ifdef _1_Lane_       
        if(DpcdRead(0x0101)!=0x81) // 1 Lane
                {
                DpcdWrite(0x0101,0x81);
                }
#endif
       
        if(DpcdRead(0x010a)!=0x00)
                {
                DpcdWrite(0x010a,0x00);
                }
       
        DpcdWrite(0x0102,0x00);
        DpcdWrite(0x0102,0x01); // sent TPS1
        DpcdWrite(0x0103,0x00);

#ifdef _2_Lane_       
        DpcdWrite(0x0104,0x00);
#endif

        if(DpcdRead(0x0102)!=0x01)
                {
                DpcdWrite(0x0102,0x01);
                }
       
        mdelay(16);
        DPCD0204H=DpcdRead(0x0204);
        DPCD0202H=DpcdRead(0x0202);
       
        swing_adj_cnt=0x05;

#ifdef _2_Lane_       
        DPCD0202H=DPCD0202H&0x11;// 2 Lane 0x11 ; 1 Lane 0x01
       
        while(((DPCD0202H&0x11)!=0x11)&&(swing_adj_cnt>0))// 1080P 0x11 ; 1366 0x01
#endif

#ifdef _1_Lane_       
        DPCD0202H=DPCD0202H&0x01;// 2 Lane 0x11 ; 1 Lane 0x01
       
        while(((DPCD0202H&0x01)!=0x01)&&(swing_adj_cnt>0))// 1080P 0x11 ; 1366 0x01
#endif
        {
                DPCD0206H=DpcdRead(0x0206);
                adj_swing();
                swing_adj_cnt--;
                mdelay(1);
                DPCD0202H=DpcdRead(0x0202);
#ifdef _2_Lane_       
                DPCD0202H=DPCD0202H&0x11;// 2 Lane 0x11 ; 1 Lane 0x01
#endif

#ifdef _1_Lane_       
                DPCD0202H=DPCD0202H&0x01;// 2 Lane 0x11 ; 1 Lane 0x01
#endif
        }
       
//        HDMI_WriteI2C_Byte(0xff,0x82);   //for debug
//        HDMI_WriteI2C_Byte(0x1b,DPCD0202H);

#ifdef _2_Lane_
        if(DPCD0202H==0x11)// 2 Lane 0x11 ; 1 Lane 0x01
#endif

#ifdef _1_Lane_
        if(DPCD0202H==0x01)// 2 Lane 0x11 ; 1 Lane 0x01
#endif
                {
                HDMI_WriteI2C_Byte(0xff,0x80);//register bank
                HDMI_WriteI2C_Byte(0x04,0x18);        

                HDMI_WriteI2C_Byte(0xff,0x84);//register bank
                HDMI_WriteI2C_Byte(0x14,0x04);                       
                HDMI_WriteI2C_Byte(0x14,0x84);
                HDMI_WriteI2C_Byte(0x14,0x88); //0x88

                DpcdWrite(0x0102,0x02);      // sent TPS2
                if(DpcdRead(0x0102)!=0x02)
                        {
                        DpcdWrite(0x0102,0x02);
                        }
               
                mdelay(16);
                DPCD0204H=DpcdRead(0x0204);
                DPCD0202H=DpcdRead(0x0202);
               
                swing_adj_cnt=0x05;

#ifdef _2_Lane_
                while(((DPCD0202H&0x77)!=0x77)&&(swing_adj_cnt>0))// 2 Lane 0x77 ; 1 Lane 0x07
#endif

#ifdef _1_Lane_
                while(((DPCD0202H&0x07)!=0x07)&&(swing_adj_cnt>0))// 2 Lane 0x77 ; 1 Lane 0x07
#endif
                        {
                        DPCD0206H=DpcdRead(0x0206);
                        HDMI_WriteI2C_Byte(0xff,0x84);//register bank
                        HDMI_WriteI2C_Byte(0x14,0x08);                       
                        HDMI_WriteI2C_Byte(0x14,0x88);
                        adj_swing();
                        swing_adj_cnt--;
                        mdelay(1);
                        DPCD0202H=DpcdRead(0x0202);
                        DPCD0204H=DpcdRead(0x0204);
                        }
        }
       
//        HDMI_WriteI2C_Byte(0xff,0x82);//register bank
//        HDMI_WriteI2C_Byte(0x1c,DPCD0202H);
       
        HDMI_WriteI2C_Byte(0xff,0x80); //register bank
        HDMI_WriteI2C_Byte(0x04,0x10);

        HDMI_WriteI2C_Byte(0xff,0x84); //register bank
        HDMI_WriteI2C_Byte(0x14,0x80);       
        HDMI_WriteI2C_Byte(0x14,0xc0);

        HDMI_WriteI2C_Byte(0xff,0x80); //register bank
        HDMI_WriteI2C_Byte(0x62,0xbf);

        HDMI_WriteI2C_Byte(0xff,0x88);//register bank

        if(HDMI_ReadI2C_Byte(0x24)!=0xc0)
                {
                HDMI_WriteI2C_Byte(0xff,0x80);//register bank
                HDMI_WriteI2C_Byte(0x62,0x3f);
                HDMI_WriteI2C_Byte(0x62,0xbf);
                }
       
        DpcdWrite(0x0102,0x00); // sent data
       
        if(DpcdRead(0x0102)!=0x00)
                {
                DpcdWrite(0x0102,0x00);
                }
       
        if(DpcdRead(0x0600)!=0x01)
                {
                DpcdWrite(0x0600,0x01); //
                }
       
        if(DpcdRead(0x010a)!=0x00)
                {
                DpcdWrite(0x010a,0x00); //
                }

        DPCD0202H=DpcdRead(0x0202);
       
}


/*void reset_lt8911(void)
{
GPIO_WriteLow(GPIOA,GPIO_PIN_1);
delay1ms(150);
GPIO_WriteHigh(GPIOA,GPIO_PIN_1);
delay1ms(150);

}*/
void lt8911_hw_enable(void){
       
        printk("lt8911_hw_enable****\n");
        if (!lt8911->pdata->pwron) {
                gpio_set_value(lt8911->pdata->dvdd33_en_pin,lt8911->pdata->dvdd33_en_val);
                msleep(5);
                gpio_set_value(lt8911->pdata->dvdd18_en_pin,lt8911->pdata->dvdd18_en_val);
                gpio_set_value(lt8911->pdata->edp_en_pin,1);
                msleep(20);
                gpio_set_value(lt8911->pdata->edp_rst_pin,1);
                msleep(50);
                gpio_set_value(lt8911->pdata->edp_rst_pin,0);
                msleep(50);
                gpio_set_value(lt8911->pdata->edp_rst_pin,1);
                lt8911->pdata->pwron = true;
        }
        lt8911->edp_anx_init(lt8911->client);
}

void lt8911_hw_disable(void){

        printk("LT8911_hw_disable****\n");
        gpio_set_value(lt8911->pdata->dvdd33_en_pin,!lt8911->pdata->dvdd33_en_val);
        gpio_set_value(lt8911->pdata->dvdd18_en_pin,!lt8911->pdata->dvdd18_en_val);
        gpio_set_value(lt8911->pdata->edp_en_pin,0);
        gpio_set_value(lt8911->pdata->edp_rst_pin,0);
        lt8911->pdata->pwron = false;

}
/*static int edp_reg_show(struct seq_file *s, void *v)
{
        int i = 0;
        char val;
        struct lt8911 *lt8911 = s->private;
        if(!lt8911)
        {
                printk(KERN_ERR "no edp device!\n");
                return 0;
        }
       
        seq_printf(s,"0x70:\n");
        for(i=0;i< MAX_REG;i++)
        {
                HDMI_ReadI2C_Byte(&val);
                seq_printf(s,"0x%02x>>0x%02x\n",i,val);
        }
       
        seq_printf(s,"\n0x72:\n");
        for(i=0;i< MAX_REG;i++)
        {
                HDMI_ReadI2C_Byte(&val);
                seq_printf(s,"0x%02x>>0x%02x\n",i,val);
        }
        return 0;
}*/       

/*static int lt8911_power_ctl(struct lt8911_platform_data*pdata)
{
       int ret;
       ret = gpio_request(pdata->dvdd33_en_pin, "dvdd33_en_pin");
       if (ret != 0) {
             gpio_free(pdata->dvdd33_en_pin);
             printk(KERN_ERR "request dvdd33 en pin fail!\n");
             return -1;
       } else {
             gpio_direction_output(pdata->dvdd33_en_pin, pdata->dvdd33_en_val);
       }
       mdelay(5);

       ret = gpio_request(pdata->dvdd18_en_pin, "dvdd18_en_pin");
       if (ret != 0) {
             gpio_free(pdata->dvdd18_en_pin);
             printk(KERN_ERR "request dvdd18 en pin fail!\n");
             return -1;
       } else {
             gpio_direction_output(pdata->dvdd18_en_pin, pdata->dvdd18_en_pin);
       }
          
           ret = gpio_request(pdata->edp_en_pin, "edp_en_pin");
       if (ret != 0) {
             gpio_free(pdata->edp_en_pin);
             printk(KERN_ERR "request en pin fail!\n");
             return -1;
       } else {
             gpio_direction_output(pdata->edp_en_pin, 1);
             msleep(20);
       }

       ret = gpio_request(pdata->edp_rst_pin, "edp_rst_pin");
       if (ret != 0) {
             gpio_free(pdata->edp_rst_pin);
             printk(KERN_ERR "request rst pin fail!\n");
             return -1;
       } else {
                   gpio_direction_output(pdata->edp_rst_pin, 1);
                   msleep(50);
             gpio_direction_output(pdata->edp_rst_pin, 0);
             msleep(50);
             gpio_direction_output(pdata->edp_rst_pin, 1);
       }
       pdata->pwron = true;
       return 0;

}

static void lt8911_parse_dt(struct lt8911 *lt8911)
{
        struct device_node *np = lt8911->client->dev.of_node;
        struct lt8911_platform_data *pdata;
        enum of_gpio_flags dvdd33_flags,dvdd18_flags,rst_flags,vcc_flags;
        pdata = devm_kzalloc(&lt8911->client->dev,
                        sizeof(struct lt8911_platform_data ), GFP_KERNEL);
        if (!pdata) {
                dev_err(&lt8911->client->dev,
                        "failed to allocate platform data\n");
                return ;
        }
        pdata->dvdd33_en_pin = of_get_named_gpio_flags(np, "dvdd33-gpio", 0, &dvdd33_flags);
        pdata->dvdd18_en_pin = of_get_named_gpio_flags(np, "dvdd18-gpio", 0, &dvdd18_flags);
        pdata->edp_rst_pin = of_get_named_gpio_flags(np, "reset-gpio", 0, &rst_flags);
        pdata->edp_en_pin = of_get_named_gpio_flags(np, "vcc-gpio", 0, &vcc_flags);
        pdata->dvdd33_en_val = (dvdd33_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
        pdata->dvdd18_en_val = (dvdd18_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
        pdata->power_ctl = lt8911_power_ctl;
        lt8911->pdata = pdata;
       
}*/

//---------------------------------------------//


// MIPI输入点1920x01080 eDP屏的 LT8911/B 寄存器设置:

void lt8911_open(void)
{
        printk("lt8911_open\n");
        lt8911_hw_enable();// 刷寄存器之前,先Reset LT8911/B ,用GPIO 先拉低LT8911/B的复位脚 150ms左右,再拉高,保持150ms

        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x00,0x04);

        HDMI_WriteI2C_Byte(0xff,0x80);//register bank
        HDMI_WriteI2C_Byte(0x7a,0x07);
        HDMI_WriteI2C_Byte(0x71,0x36);
        HDMI_WriteI2C_Byte(0x72,0x00);
        HDMI_WriteI2C_Byte(0x73,0x00);

        HDMI_WriteI2C_Byte(0x63,0x7f);
        HDMI_WriteI2C_Byte(0x63,0xff);

        ///////////txpll_analog///////
        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x0e,0x37);
        HDMI_WriteI2C_Byte(0x01,0x18);
        HDMI_WriteI2C_Byte(0x02,0x42);
        HDMI_WriteI2C_Byte(0x04,0x00);
        HDMI_WriteI2C_Byte(0x04,0x01);

       
        HDMI_WriteI2C_Byte(0xff,0x80);//register bank
        HDMI_WriteI2C_Byte(0x61,0x7f);
        HDMI_WriteI2C_Byte(0x61,0xff);
       
        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x05,0x13);

        //////////txpll_digtal////////
        HDMI_WriteI2C_Byte(0xff,0x80);//register bank
        HDMI_WriteI2C_Byte(0x74,0x41);
        HDMI_WriteI2C_Byte(0x75,0x03);
        HDMI_WriteI2C_Byte(0x76,0x0a);
        HDMI_WriteI2C_Byte(0x78,0x0a);

//-------------------------------------------//
        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x0e,0x37);

#ifdef _1_Lane_

        // 1 Lane eDP Output
        HDMI_WriteI2C_Byte(0x22,0x10);// 关闭 LANE1 / LANE2 / LANE3 SWING 的电流开关
        HDMI_WriteI2C_Byte(0x23,0x3e);// 关闭 LANE1 / LANE2 / LANE3 pre-emphase 的电流开关
        HDMI_WriteI2C_Byte(0x25,0x08);       
       
        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);
        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
               
#else
        // 2 Lane eDP Output
        HDMI_WriteI2C_Byte(0x22,0x30);// 关闭 LANE2 / LANE3 SWING的电流开关
        HDMI_WriteI2C_Byte(0x23,0x3c);// 关闭 LANE2 / LANE3 pre-emphase的电流开关
        HDMI_WriteI2C_Byte(0x25,0x08);
               
        HDMI_WriteI2C_Byte(0x18,Swing_Level_0_H);
        HDMI_WriteI2C_Byte(0x19,Swing_Level_0_L);
               
        HDMI_WriteI2C_Byte(0x1a,Swing_Level_0_H);
        HDMI_WriteI2C_Byte(0x1b,Swing_Level_0_L);
       
#endif

//---------------------------------- //       

// 前面可以先打开DDS.
// #ifdef _Test_Pattern_

        #ifdef _1080P_eDP_Panel_
        HDMI_WriteI2C_Byte(0xff,0x90);//register bank
        HDMI_WriteI2C_Byte(0x4a,0x33); // 148.5MHz
        HDMI_WriteI2C_Byte(0x4b,0x33);
        HDMI_WriteI2C_Byte(0x4c,0x33);
        HDMI_WriteI2C_Byte(0x4d,0x10);
        #endif

        #ifdef _1366x768_eDP_Panel_
        HDMI_WriteI2C_Byte(0xff,0x90);//register bank
        //HDMI_WriteI2C_Byte(0x4a,0x66); // 72MHz
        //HDMI_WriteI2C_Byte(0x4b,0x66);
        //HDMI_WriteI2C_Byte(0x4c,0x66);
        HDMI_WriteI2C_Byte(0x4a,0xab); // 76.42MHz
        HDMI_WriteI2C_Byte(0x4b,0xaf);
        HDMI_WriteI2C_Byte(0x4c,0x6c);
       
        HDMI_WriteI2C_Byte(0x4d,0x10);
        #endif

// #else
//        HDMI_WriteI2C_Byte(0xff,0x90);//register bank
//        HDMI_WriteI2C_Byte(0x4d,0x00)
// #endif       
        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x09,0x01);
        HDMI_WriteI2C_Byte(0x0b,0x0b);
        HDMI_WriteI2C_Byte(0x08,0x13);

//-----------------1080P_60Hz---------------------//

        HDMI_WriteI2C_Byte(0xff,0x88);//register bank
        HDMI_WriteI2C_Byte(0x00,0x6a);
        HDMI_WriteI2C_Byte(0x04,0xff);

        HDMI_WriteI2C_Byte(0x05,(u8)(MIPI_Timing/256));//RG_HTOTAL
        HDMI_WriteI2C_Byte(0x06,(u8)(MIPI_Timing%256));//RG_HTOTAL
        HDMI_WriteI2C_Byte(0x07,(u8)((MIPI_Timing+MIPI_Timing)/256));//RG_HSTART
        HDMI_WriteI2C_Byte(0x08,(u8)((MIPI_Timing+MIPI_Timing)%256));//RG_HSTART=110
        HDMI_WriteI2C_Byte(0x09,(u8)(MIPI_Timing/256));//RG_HSPOL;RG_HSYNC_WIDTH        0x80-->0x00
        HDMI_WriteI2C_Byte(0x0a,(u8)(MIPI_Timing%256));//RG_HSYNC_WIDTH=60
        HDMI_WriteI2C_Byte(0x0b,(u8)(MIPI_Timing/256));//RG_HWIDTH
        HDMI_WriteI2C_Byte(0x0c,(u8)(MIPI_Timing%256));//RG_HWIDTH
        HDMI_WriteI2C_Byte(0x0d,(u8)(MIPI_Timing/256));//RG_VTOTAL
        HDMI_WriteI2C_Byte(0x0e,(u8)(MIPI_Timing%256));//RG_VTOTAL
       
        HDMI_WriteI2C_Byte(0x0f,0x00);//RG_TOP_VTOTAL //fiexd
        HDMI_WriteI2C_Byte(0x10,0x00);//RG_TOP_VTOTAL        //fixed
       
        HDMI_WriteI2C_Byte(0x11,(u8)((MIPI_Timing+MIPI_Timing)/256));//RG_VSTART
        HDMI_WriteI2C_Byte(0x12,(u8)((MIPI_Timing+MIPI_Timing)%256));//RG_VSTART
        HDMI_WriteI2C_Byte(0x13,(u8)(MIPI_Timing/256));//RG_VSPOL;RG_VSYNC_WIDTH0x80-->0x00       
        HDMI_WriteI2C_Byte(0x14,(u8)(MIPI_Timing%256));//RG_VSYNC_WIDTH
        HDMI_WriteI2C_Byte(0x15,(u8)(MIPI_Timing/256));//RG_VHEIGTH
        HDMI_WriteI2C_Byte(0x16,(u8)(MIPI_Timing%256));//RG_VHEIGTH

#ifdef _6_Bit_ColorDepth_
        HDMI_WriteI2C_Byte(0x17,0x00);// LVDS Color Depth:   6 bit: 0x00 ;   8 bit: 0x08
        HDMI_WriteI2C_Byte(0x18,0x00);// LVDS Color Depth:   6 bit: 0x00 ;   8 bit: 0x20
#endif

#ifdef _8_Bit_ColorDepth_
        HDMI_WriteI2C_Byte(0x17,0x08);// LVDS Color Depth:   6 bit: 0x00 ;   8 bit: 0x08
        HDMI_WriteI2C_Byte(0x18,0x20);// LVDS Color Depth:   6 bit: 0x00 ;   8 bit: 0x20
#endif

        HDMI_WriteI2C_Byte(0x19,0x00);
        HDMI_WriteI2C_Byte(0x1a,0x80);
        HDMI_WriteI2C_Byte(0x1e,0x30);
        HDMI_WriteI2C_Byte(0x21,0x00);
        HDMI_WriteI2C_Byte(0x2c,0xdf);
        HDMI_WriteI2C_Byte(0x2d,0x00);

        HDMI_WriteI2C_Byte(0x4b,0xfe);

        HDMI_WriteI2C_Byte(0x2e,(u8)((MIPI_Timing+MIPI_Timing)%256));//RG_GCM_DE_TOP
        HDMI_WriteI2C_Byte(0x2f,(u8)((MIPI_Timing+MIPI_Timing)/256));//RG_GCM_DE_DLY
        HDMI_WriteI2C_Byte(0x30,(u8)((MIPI_Timing+MIPI_Timing)%256));//RG_GCM_DE_DLY
        HDMI_WriteI2C_Byte(0x31,(u8)(MIPI_Timing/256));//RG_GCM_DE_CNT
        HDMI_WriteI2C_Byte(0x32,(u8)(MIPI_Timing%256));//RG_GCM_DE_CNT
        HDMI_WriteI2C_Byte(0x33,(u8)(MIPI_Timing/256));//RG_GCM_DE_LIN
        HDMI_WriteI2C_Byte(0x34,(u8)(MIPI_Timing%256));//RG_GCM_DE_LIN
        HDMI_WriteI2C_Byte(0x35,(u8)(MIPI_Timing/256));//RG_GCM_HTOTAL
        HDMI_WriteI2C_Byte(0x36,(u8)(MIPI_Timing%256));//RG_GCM_HTOTAL

#ifdef _Test_Pattern_

        HDMI_WriteI2C_Byte(0x37,0x18+(u8)(MIPI_Timing/256));//1c:pre-pattern,0c:mipi pattern;RG_GCM_VTOTAL
#else

        HDMI_WriteI2C_Byte(0x37,0x08+(u8)(MIPI_Timing/256));//1c:pre-pattern,0c:mipi pattern;RG_GCM_VTOTAL
#endif

        HDMI_WriteI2C_Byte(0x38,(u8)(MIPI_Timing%256));//RG_GCM_VTOTAL
        HDMI_WriteI2C_Byte(0x39,0x00);//reseve
        HDMI_WriteI2C_Byte(0x3a,((u8)(MIPI_Timing%256))*4 + (u8)(MIPI_Timing/256));//RG_GCM_VWIDTH;RG_GCM_HWIDTH
        HDMI_WriteI2C_Byte(0x3b,(u8)(MIPI_Timing%256));//RG_GCM_HWIDTH

       
////////////////////Nvid//////////////
        HDMI_WriteI2C_Byte(0xff,0x8c); //register bank
        HDMI_WriteI2C_Byte(0x00,0x00);
        HDMI_WriteI2C_Byte(0x01,0x80);
        HDMI_WriteI2C_Byte(0x02,0x00);

//-----------------Training-----------------------------//

        LT8911_AUX_Training();
#ifdef _2_Lane_
        if(DPCD0202H!=0x77)
#endif

#ifdef _1_Lane_
        if(DPCD0202H!=0x07)
#endif
        LT8911_AUX_Training();
             
//        HDMI_WriteI2C_Byte(0xff,0x88);//register bank      
//        HDMI_WriteI2C_Byte(0x1e,0x30);         
//        HDMI_WriteI2C_Byte(0x4b,0xfe);

//-----------------------------------------------//

        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x27,0x80);
        HDMI_WriteI2C_Byte(0x28,0xa4);
        HDMI_WriteI2C_Byte(0x29,0xd2);
        HDMI_WriteI2C_Byte(0x2a,0x04);
        HDMI_WriteI2C_Byte(0x2b,0x7e);
        HDMI_WriteI2C_Byte(0x2c,0x02);
        HDMI_WriteI2C_Byte(0x2d,0x02);
        HDMI_WriteI2C_Byte(0x2e,0xaa);
        HDMI_WriteI2C_Byte(0x2f,0x02);
        HDMI_WriteI2C_Byte(0x30,0xaa);
        HDMI_WriteI2C_Byte(0x31,0x4b);
        HDMI_WriteI2C_Byte(0x32,0x43);
        HDMI_WriteI2C_Byte(0x33,0x20);
        HDMI_WriteI2C_Byte(0x34,0x00);
        HDMI_WriteI2C_Byte(0x35,0x80);
        HDMI_WriteI2C_Byte(0x36,0xa4);
        HDMI_WriteI2C_Byte(0x37,0xd2);
        HDMI_WriteI2C_Byte(0x38,0x00);
        HDMI_WriteI2C_Byte(0x39,0x36);
        HDMI_WriteI2C_Byte(0x3a,0x00);

//--------------------------------------------//

        HDMI_WriteI2C_Byte(0xff,0x90);//register bank
        HDMI_WriteI2C_Byte(0x01,0x04);
        HDMI_WriteI2C_Byte(0x02,0x04);
        HDMI_WriteI2C_Byte(0x03,0x04);
        HDMI_WriteI2C_Byte(0x04,0xc8);
        HDMI_WriteI2C_Byte(0x05,0x00);
        HDMI_WriteI2C_Byte(0x06,0x0b);
        HDMI_WriteI2C_Byte(0x0b,_MIPI_Lane_%4);// 00:4 Lane;01:1 Lane;02:2 Lane;03:3 Lane
        HDMI_WriteI2C_Byte(0x0c,0x00);// 3210
        HDMI_WriteI2C_Byte(0x10,0x03);
        HDMI_WriteI2C_Byte(0x11,0x03);

        HDMI_WriteI2C_Byte(0x12,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x13,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x14,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x15,(u8)(MIPI_Timing/256));
        HDMI_WriteI2C_Byte(0x16,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x17,(u8)(MIPI_Timing/256));

        HDMI_WriteI2C_Byte(0x18,0x00);
        HDMI_WriteI2C_Byte(0x19,0x01);
        HDMI_WriteI2C_Byte(0x1a,0x17);
        HDMI_WriteI2C_Byte(0x2b,0x0b);
        HDMI_WriteI2C_Byte(0x2c,0x0c);

        HDMI_WriteI2C_Byte(0x31,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x32,(u8)(MIPI_Timing/256));
        HDMI_WriteI2C_Byte(0x33,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x34,(u8)(MIPI_Timing/256));
        HDMI_WriteI2C_Byte(0x35,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x36,(u8)(MIPI_Timing/256));
        HDMI_WriteI2C_Byte(0x37,(u8)((MIPI_Timing-MIPI_Timing-MIPI_Timing-MIPI_Timing)%256));
        HDMI_WriteI2C_Byte(0x38,(u8)((MIPI_Timing-MIPI_Timing-MIPI_Timing-MIPI_Timing)/256));
        HDMI_WriteI2C_Byte(0x39,(u8)(MIPI_Timing%256));
        HDMI_WriteI2C_Byte(0x3a,(u8)(MIPI_Timing/256));
        HDMI_WriteI2C_Byte(0x3b,(u8)((MIPI_Timing-MIPI_Timing-MIPI_Timing-MIPI_Timing)%256));
        HDMI_WriteI2C_Byte(0x3c,(u8)((MIPI_Timing-MIPI_Timing-MIPI_Timing-MIPI_Timing)/256));

        HDMI_WriteI2C_Byte(0x1b,0x90);
        HDMI_WriteI2C_Byte(0x1c,0x01);
        HDMI_WriteI2C_Byte(0x1d,0x68);
        HDMI_WriteI2C_Byte(0x1e,0x01);
        HDMI_WriteI2C_Byte(0x1f,0x5e);
        HDMI_WriteI2C_Byte(0x20,0x01);
        HDMI_WriteI2C_Byte(0x21,0x54);
        HDMI_WriteI2C_Byte(0x22,0x01);
        HDMI_WriteI2C_Byte(0x23,0x90);
        HDMI_WriteI2C_Byte(0x24,0x01);
        HDMI_WriteI2C_Byte(0x25,0x68);
        HDMI_WriteI2C_Byte(0x26,0x01);
        HDMI_WriteI2C_Byte(0x27,0x5e);
        HDMI_WriteI2C_Byte(0x28,0x01);
        HDMI_WriteI2C_Byte(0x29,0x54);
        HDMI_WriteI2C_Byte(0x2a,0x01);
        HDMI_WriteI2C_Byte(0x3d,0x64);
        HDMI_WriteI2C_Byte(0x3f,0x00);
        HDMI_WriteI2C_Byte(0x40,0x04);
        HDMI_WriteI2C_Byte(0x41,0x00);
        HDMI_WriteI2C_Byte(0x42,0x59);
        HDMI_WriteI2C_Byte(0x43,0x00);
        HDMI_WriteI2C_Byte(0x44,0xf2);
        HDMI_WriteI2C_Byte(0x45,0x06);
        HDMI_WriteI2C_Byte(0x46,0x00);
        HDMI_WriteI2C_Byte(0x47,0x72);
        HDMI_WriteI2C_Byte(0x48,0x45);
        HDMI_WriteI2C_Byte(0x49,0x00);

        HDMI_WriteI2C_Byte(0x60,0x08);
        HDMI_WriteI2C_Byte(0x61,0x00);
        HDMI_WriteI2C_Byte(0x62,0xb2);
        HDMI_WriteI2C_Byte(0x63,0x00);
        HDMI_WriteI2C_Byte(0x64,0xe4);
        HDMI_WriteI2C_Byte(0x65,0x0d);
        HDMI_WriteI2C_Byte(0x66,0x00);
        HDMI_WriteI2C_Byte(0x67,0xe4);
        HDMI_WriteI2C_Byte(0x68,0x8a);
        HDMI_WriteI2C_Byte(0x69,0x00);
        HDMI_WriteI2C_Byte(0x6a,0x0b);
        HDMI_WriteI2C_Byte(0x1a,0x4f);
        HDMI_WriteI2C_Byte(0x6b,0x04);


#ifdef _Test_Pattern_

//        前面已经设置过DDS了,这里不需设置了。
//        HDMI_WriteI2C_Byte(0xff,0x90); //register bank
//        HDMI_WriteI2C_Byte(0x4a,0x33);
//        HDMI_WriteI2C_Byte(0x4b,0x33);
//        HDMI_WriteI2C_Byte(0x4c,0xd3);
//        HDMI_WriteI2C_Byte(0x4d,0x10);

#else
        HDMI_WriteI2C_Byte(0xff,0x90); //register bank
//        HDMI_WriteI2C_Byte(0x4a,0x00);
//        HDMI_WriteI2C_Byte(0x4b,0x00);
//        HDMI_WriteI2C_Byte(0x4c,0x00);
        HDMI_WriteI2C_Byte(0x4d,0x00);// 关闭DDS
#endif

//---------------------------------------//
        HDMI_WriteI2C_Byte(0xff,0x80);//register bank
        HDMI_WriteI2C_Byte(0x60,0xde);
        HDMI_WriteI2C_Byte(0x60,0xff);

//------------------------------------------//

//        For test
        HDMI_WriteI2C_Byte(0xff,0x90);//register bank
        HDMI_WriteI2C_Byte(0x07,0xc0);

        HDMI_WriteI2C_Byte(0xff,0x80);//register bank
        HDMI_WriteI2C_Byte(0x94,0x00);
        HDMI_WriteI2C_Byte(0x95,0x00);

        HDMI_WriteI2C_Byte(0xff,0x81);//register bank
        HDMI_WriteI2C_Byte(0x3f,0x02);
        HDMI_WriteI2C_Byte(0x3e,0xff);
        HDMI_WriteI2C_Byte(0x3d,0x03);
        HDMI_WriteI2C_Byte(0x2b,0x7f);
//----------------------------------------//

}
EXPORT_SYMBOL(lt8911_open);

void lt8911_close(void)
{
        lt8911_hw_disable();
}
EXPORT_SYMBOL(lt8911_close);
/*static int edp_reg_open(struct inode *inode, struct file *file)
{
        //struct lt8911 *lt8911 = inode->i_private;
        lt8911_open();
        return 0;
}
static const struct file_operations edp_reg_fops = {
        .owner                = THIS_MODULE,
        .open                = edp_reg_open,
        .read                = seq_read,
        .llseek                = seq_lseek,
        .release        = single_release,
};*/
/*#ifdef CONFIG_HAS_EARLYSUSPEND
static void lt8911_early_suspend(struct early_suspend *h)
{
        lt8911_close();
}

static void lt8911_late_resume(struct early_suspend *h)
{
        lt8911_open();
}
#endif*/


static intlt8911_probe(struct i2c_client *client,
      const struct i2c_device_id *id)
{
        //struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
        //struct lt8911 *lt8911 = NULL;
       
    pr_info("%s()\n", __FUNCTION__);
       
    if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
      printk(KERN_INFO "i2c_check_functionality error\n");
      goto exit;
    }
        /*lt8911 = kzalloc(sizeof(struct lt8911), GFP_KERNEL);
        if (lt8911 == NULL) {
                dev_err(&client->dev, "alloc for struct lt8911fail\n");
                return -ENOMEM;
        }*/
                lt8911_client = client;
                /*lt8911->pdata = client->dev.platform_data;
        if (!lt8911->pdata) {
                lt8911_parse_dt(lt8911);
        }
        i2c_set_clientdata(client,lt8911);
        if(lt8911->pdata->power_ctl)
                lt8911->pdata->power_ctl(lt8911->pdata);
       
                debugfs_create_file("edp-reg", S_IRUSR,NULL,lt8911,&edp_reg_fops);

#ifdef CONFIG_HAS_EARLYSUSPEND
        lt8911->early_suspend.suspend = lt8911_early_suspend;
        lt8911->early_suspend.resume = lt8911_late_resume;
            lt8911->early_suspend.level = EARLY_SUSPEND_LEVEL_STOP_DRAWING;
        register_early_suspend(&lt8911->early_suspend);
#endif

        edp = lt8911;*/

        dev_info(&client->dev, "edp lt8911 probe ok \n");
   
    return 0;

exit:
          return -1;
}

/*static struct mipi_dsi_ops lt8911_ops = {
        .id = MODULE_I2C_ADDR,
        .name = MODULE_NAME,
        .get_id = lt8911_get_id,
        .power_up = lt8911_power_up,
        .power_down = lt8911_power_down,
       
};*/

static const unsigned shortlt8911_addresses[] = {
    MODULE_I2C_ADDR,
    I2C_CLIENT_END,
};

static const struct i2c_device_id lt8911_id[] = {
    { MODULE_NAME, 0 },
    { }
};

/*static struct of_device_id lt8911_dt_ids[] = {
        { .compatible = "lt8911" },
        { }
};*/

static struct i2c_driver lt8911_driver = {
    .driver = {
      .owner    = THIS_MODULE,
      .name    = MODULE_NAME,
    },
    .id_table    = lt8911_id,
    .probe      = lt8911_probe,
};

static struct i2c_board_info lt8911_board_info={
    .type = MODULE_NAME,
    .addr = MODULE_I2C_ADDR,
};


//static struct i2c_client *lt8911_client;

int __init lt8911_i2c_init(void)
{
    struct i2c_adapter *i2c_adap;
    unsigned int cfg_i2c_adap_id;
    cfg_i2c_adap_id = 1;
    i2c_adap = i2c_get_adapter(cfg_i2c_adap_id);
    lt8911_client = i2c_new_device(i2c_adap, &lt8911_board_info);
    i2c_put_adapter(i2c_adap);
        return i2c_add_driver(&lt8911_driver);
   
}
fs_initcall(lt8911_i2c_init);
void __exit lt8911_i2c_exit(void)
{
        //del_dsi_ops(lt8911_ops);
        //lt8911_lcd_manager = NULL;
    i2c_del_driver(&lt8911_driver);
    //i2c_unregister_device(lt8911_client);
}
module_exit(lt8911_i2c_exit);

xi0325 发表于 2017-3-23 19:00:06

xi0325 发表于 2017-3-23 18:57
/*******************************************************

// I2C_Adr = 0x52;// bit0 是读写标志 ...

自己参照dp_anx6345.c文件移植的,也不知道对不对

loading 发表于 2017-3-23 22:37:21

xi0325 发表于 2017-3-23 19:00
自己参照dp_anx6345.c文件移植的,也不知道对不对

1. dts 里面添加节点了吗?
2. 具体问题是什么?
驱动可以正常加载了吗? 或是只有屏不亮

xi0325 发表于 2017-3-24 09:17:04

loading 发表于 2017-3-23 22:37
1. dts 里面添加节点了吗?
2. 具体问题是什么?
驱动可以正常加载了吗? 或是只有屏不亮

1,dts里边有添加节点
lt8911@52 {
                compatible = "rockchip,lt8911";
                reg = <0x52>;
                gpio-power = <&gpio8 GPIO_A1 GPIO_ACTIVE_HIGH>;
                gpio-reset = <&gpio8 GPIO_A2 GPIO_ACTIVE_HIGH>;
                status = "okay";
        }
2,现在是8911B都还没通

loading 发表于 2017-3-27 09:49:55

xi0325 发表于 2017-3-24 09:17
1,dts里边有添加节点
lt8911@52 {
                compatible = "rockchip,lt8911";


1. 确认驱动加载成功
2. 确认i2c 可以正常读写
3. 然后进行寄存器的读写

肥匪斐_Leon 发表于 2018-1-24 15:29:02

现在这个driver 有porting成功吗?能否借鉴一下 谢谢~~~~

肥匪斐_Leon 发表于 2018-1-26 14:29:20

xi0325 发表于 2017-3-23 18:57
/*******************************************************

// I2C_Adr = 0x52;// bit0 是读写标志 ...

lt8911_i2c_init 这个函数写的有问题
页: [1]
查看完整版本: 有谁调过显示屏转换IC??