#ifndef BUILD_LK
#include <linux/string.h>
#else
#include <string.h>
#endif
#ifdef BUILD_LK
#include <platform/mt_gpio.h>
#else
#include <linux/delay.h>
#include <linux/types.h>
#endif
#include "lcm_drv.h"
typedef unsigned char kal_uint8;
typedef unsigned short kal_uint16;
typedef unsigned int kal_uint32;
typedef unsigned long long kal_uint64;
typedef char kal_char;
#ifdef BUILD_LK
#define DEBUG printf
#else
#define DEBUG printk
#endif
#ifdef BUILD_LK
//extern void lt8911b_write_byte( kal_uint8 RegAddr, kal_uint8 data ); // IIC 写入操作,IIC速率不要超过100KHz
#define eDP_LCD_RST_EN GPIO_LCM_RST//(GPIO20|0x80000000)
#define eDP_LCD_POWER_EN GPIO_LCM_PWR//(GPIO78|0x80000000)
extern kal_uint32 lt8911b_write_byte(kal_uint8 addr, kal_uint8 value);
extern kal_uint32 lt8911b_read_byte (kal_uint8 addr, kal_uint8 *dataBuffer);
extern void mdelay (unsigned long msec);
#else
extern int lt8911b_write_byte(kal_uint8 cmd, kal_uint8 writeData);
extern int lt8911b_read_byte(kal_uint8 cmd, kal_uint8 *returnData);
extern int lt8911exb_gpio_configure(bool on);
#endif
#define MDELAY(n) (mdelay(n))
#define SCRAMBLE_MODE 0x00 //0x80: edp, 0x00: dp
//#define _pcr_mk_printk_
//#define _htotal_stable_check_
//#define _EDP_Pattern_
#define _link_train_enable_
#define MSA_SW_MODE 0x80 //MSA from register
#define MSA_HW_MODE 0x00 //MSA from video check
#define EDP_IDLE_PTN_ON 0x04
#define EDP_IDLE_PTN_OFF 0x00
struct video_timing {
u16 hfp;
u16 hs;
u16 hbp;
u16 hact;
u16 htotal;
u16 vfp;
u16 vs;
u16 vbp;
u16 vact;
u16 vtotal;
u32 pclk_khz;
};
#define LANE_CNT 2
#define PCR_PLL_PREDIV 0x40
#define PCR_M 0x17 //148.5M //hfp, hs, hbp,hact,htotal,vfp, vs, vbp, vact,vtotal,
//const struct video_timing video ={88, 44, 148,1920, 2200, 4, 5, 36, 1080, 1125, 148500};
const struct video_timing video_format ={48, 32, 80, 1920, 2080, 11, 5, 15, 1080, 1111, 13850};
void LT8911_Reset(void)
{
#ifdef BUILD_LK
mt_set_gpio_mode(eDP_LCD_POWER_EN, GPIO_MODE_00);
mt_set_gpio_dir(eDP_LCD_POWER_EN, GPIO_DIR_OUT);
mt_set_gpio_out(eDP_LCD_POWER_EN, GPIO_OUT_ONE);
MDELAY(100);
mt_set_gpio_mode(eDP_LCD_RST_EN, GPIO_MODE_00);
mt_set_gpio_dir(eDP_LCD_RST_EN, GPIO_DIR_OUT);
mt_set_gpio_out(eDP_LCD_RST_EN, GPIO_OUT_ONE);
MDELAY(100);
mt_set_gpio_out(eDP_LCD_RST_EN, GPIO_OUT_ZERO);
MDELAY(100);
mt_set_gpio_out(eDP_LCD_RST_EN, GPIO_OUT_ONE);
MDELAY(100);
#else
lt8911exb_gpio_configure(true);
#endif
}
void LT8911_ChipID(void)
{
unsigned char cmdBuffer;
unsigned char VenID[3];
DEBUG("[LK/LCM]xxxxxxx %s enter\n", __func__);
lt8911b_write_byte(0xff,0x81);//register bank
lt8911b_write_byte(0x08,0x7f);
cmdBuffer = 0x00;
lt8911b_read_byte(cmdBuffer, &VenID[0]);
cmdBuffer = 0x01;
lt8911b_read_byte(cmdBuffer, &VenID[1]);
cmdBuffer = 0x02;
lt8911b_read_byte(cmdBuffer, &VenID[2]);
DEBUG("[LK/LCM]xxxxxxx %s CHIPid:%x %x %x\n", __func__, VenID[0], VenID[1], VenID[2]);
}
void LT8911_SetVideoTiming(void)
{
u32 pclk_khz;
u8 dessc_m;
//edp msa
lt8911b_write_byte(0xff,0xa8);
lt8911b_write_byte(0x2d,0x88); //bit[7]1 = register msa, 0 = hardware msa
#ifdef _Msa_Active_Only_
lt8911b_write_byte(0x05,0x00);
lt8911b_write_byte(0x06,0x00);//htotal
lt8911b_write_byte(0x07,0x00);
lt8911b_write_byte(0x08,0x00);//h_start
lt8911b_write_byte(0x09,0x00);
lt8911b_write_byte(0x0a,0x00); //hsa
lt8911b_write_byte(0x0b,(u8)(video_format.hact/256));
lt8911b_write_byte(0x0c,(u8)(video_format.hact%256)); //hactive
lt8911b_write_byte(0x0d,0x00);
lt8911b_write_byte(0x0e,0x00);//vtotal
lt8911b_write_byte(0x11,0x00);
lt8911b_write_byte(0x12,0x00);
lt8911b_write_byte(0x14,0x00);
lt8911b_write_byte(0x15,(u8)(video_format.vact/256));
lt8911b_write_byte(0x16,(u8)(video_format.vact%256)); //vactive
#else
lt8911b_write_byte(0x05,(u8)(video_format.htotal/256));
lt8911b_write_byte(0x06,(u8)(video_format.htotal%256));//htotal
lt8911b_write_byte(0x07,(u8)((video_format.hs+video_format.hbp)/256));
lt8911b_write_byte(0x08,(u8)((video_format.hs+video_format.hbp)%256));//h_start
lt8911b_write_byte(0x09,(u8)(video_format.hs/256));
lt8911b_write_byte(0x0a,(u8)(video_format.hs%256)); //hsa
lt8911b_write_byte(0x0b,(u8)(video_format.hact/256));
lt8911b_write_byte(0x0c,(u8)(video_format.hact%256)); //hactive
lt8911b_write_byte(0x0d,(u8)(video_format.vtotal/256));
lt8911b_write_byte(0x0e,(u8)(video_format.vtotal%256));//vtotal
lt8911b_write_byte(0x11,(u8)((video_format.vs+video_format.vbp)/256));
lt8911b_write_byte(0x12,(u8)((video_format.vs+video_format.vbp)%256));//v_start
lt8911b_write_byte(0x14,(u8)(video_format.vs%256)); //vsa
lt8911b_write_byte(0x15,(u8)(video_format.vact/256));
lt8911b_write_byte(0x16,(u8)(video_format.vact%256)); //vactive
#endif
// ldvd de only mode to regenerate h/v sync.
lt8911b_write_byte(0xff,0xd8);
lt8911b_write_byte(0x20,(u8)(video_format.hfp/256));
lt8911b_write_byte(0x21,(u8)(video_format.hfp%256));
lt8911b_write_byte(0x22,(u8)(video_format.hs/256));
lt8911b_write_byte(0x23,(u8)(video_format.hs%256));
lt8911b_write_byte(0x24,(u8)(video_format.htotal/256));
lt8911b_write_byte(0x25,(u8)(video_format.htotal%256));
lt8911b_write_byte(0x26,(u8)(video_format.vfp%256));
lt8911b_write_byte(0x27,(u8)(video_format.vs%256));
//de-sscpll to gererate pixel clock for pattern
pclk_khz = video_format.pclk_khz;
dessc_m = (pclk_khz * 4) /(25*1000);
lt8911b_write_byte(0xff,0x85);
lt8911b_write_byte(0xaa,dessc_m); //MK[30:24]
// lt8911b_write_byte(0xab,0xba); //MK[23:16]
// lt8911b_write_byte(0xac,0xe1); //MK[15:8]
// lt8911b_write_byte(0xad,0x47); //MK[7:0]
}
void LT8911_MIPI_Video_Timing(void)
{
lt8911b_write_byte(0xff,0xd0);
lt8911b_write_byte(0x0d,(u8)(video_format.vtotal/256));
lt8911b_write_byte(0x0e,(u8)(video_format.vtotal%256));//vtotal
lt8911b_write_byte(0x0f,(u8)(video_format.vact/256));
lt8911b_write_byte(0x10,(u8)(video_format.vact%256)); //vactive
lt8911b_write_byte(0x11,(u8)(video_format.htotal/256));
lt8911b_write_byte(0x12,(u8)(video_format.htotal%256));//htotal
lt8911b_write_byte(0x13,(u8)(video_format.hact/256));
lt8911b_write_byte(0x14,(u8)(video_format.hact%256)); //hactive
lt8911b_write_byte(0x15,(u8)(video_format.vs%256)); //vsa
lt8911b_write_byte(0x16,(u8)(video_format.hs%256)); //hsa
lt8911b_write_byte(0x17,(u8)(video_format.vfp/256));
lt8911b_write_byte(0x18,(u8)(video_format.vfp%256)); //vfp
lt8911b_write_byte(0x19,(u8)(video_format.hfp/256));
lt8911b_write_byte(0x1a,(u8)(video_format.hfp%256)); //hfp
}
void LT8911_Init(void)
{
u8 i;
unsigned char cmdBuffer, value;
/* init */
lt8911b_write_byte(0xff,0x81);
lt8911b_write_byte(0x08,0x7f); //i2c over aux issue
lt8911b_write_byte(0x49,0xff); //enable 0x87xx
lt8911b_write_byte(0xff,0x82); //GPIO test output
lt8911b_write_byte(0x5a,0x0e);
//for power consumption//
lt8911b_write_byte(0xff,0x81);
lt8911b_write_byte(0x05,0x06);
lt8911b_write_byte(0x43,0x00);
lt8911b_write_byte(0x44,0x1f);
lt8911b_write_byte(0x45,0xf7);
lt8911b_write_byte(0x46,0xf6);
lt8911b_write_byte(0x49,0x7f);
lt8911b_write_byte(0xff,0x82);
lt8911b_write_byte(0x12,0x33);
/* mipi Rx analog */
lt8911b_write_byte(0xff,0x82);
lt8911b_write_byte(0x32,0x51);
lt8911b_write_byte(0x35,0x62); //EQ current 0x42
lt8911b_write_byte(0x3a,0x77); //EQ 12.5db
lt8911b_write_byte(0x3b,0x77); //EQ 12.5db
lt8911b_write_byte(0x4c,0x0c);
lt8911b_write_byte(0x4d,0x00);
/* dessc_pcr pll analog */
lt8911b_write_byte(0xff,0x82);
lt8911b_write_byte(0x6a,0x43); //final setting: 0x40
lt8911b_write_byte(0x6b,PCR_PLL_PREDIV); //0x44:pre-div = 2
//lt8911b_write_byte(0x6b,0x44);
lt8911b_write_byte(0x6e,0x81);
/* dessc pll digital */
lt8911b_write_byte(0xff,0x85);
lt8911b_write_byte(0xa9,0x31);
lt8911b_write_byte(0xaa,0x17);
lt8911b_write_byte(0xab,0xba);
lt8911b_write_byte(0xac,0xe1);
lt8911b_write_byt
评论0