标签:
对于LCM驱动移植,一般分为三部曲:
1、硬件IO口配置;
2、确保LCM背光能够正常点亮;
3、LCM驱动移植;
硬件电路:
1、GPIO配置
打开 mediatek\dct\DrvGen.exe
选择 mediatek\custom\xiaoxi\kernel\dct\dct\codegen.dws 配置文件
配置LCM PWM引脚、RST复位引脚、DISP_PWM引脚和LCM电源控制引脚
2、背光灯
编译烧录后启动系统,验证LCM背光是否能正常点亮,否则无法继续调试LCD;
3、LCM驱动移植(以ili9806e为例)
(1)、在mediatek\custom\common\kernel\lcm目录下创建ili9806目录,将驱动文件拷贝到驱动文件ili9806.c到新创建的目录中;代码自动将lcm软链接到mediatek\custom\common\lk和mediatek\custom\common\uboot目录,因此无需拷贝驱动文件到lk和uboot中;
(2)、修改\mediatek\custom\common\kernel\lcm\mt65xx_lcm_list.c, 在lcm_driver_list 数组中增加:
extern LCM_DRIVER ili9806e_lcm_drv;
#if defined(ILI9806)
&ili9806e_lcm_drv, //就是ili9488.c中的LCM_DRIVER结构
#endif
(3)、打开mediatek\config\prj\ProjectConfig.mk修改:
BUILD_LK=yes
CUSTOM_KERNEL_LCM=ili9806 //对应lcm目录驱动的子目录名
CUSTOM_LK_LCM=ili9806 //对应lcm目录驱动的子目录名
CUSTOM_UBOOT_LCM=ili9806 //对应lcm目录驱动的子目录名
LCM_WIDTH=480
LCM_HEIGHT=800
系统编译的时候,编译器会根据CUSTOM_KERNEL_LCM、CUSTOM_LK_LCM、CUSTOM_UBOOT_LCM找到mediatek\custom\common\kernel\lcm\ili9806目录,拷贝mediatek\custom\out\pro\kernel\lcm目录,参与系统的编译,所以对于驱动文件名有没命名要求;lk和uboot同理;
注:系统此时也会产生ILI9806的环境变量,这就是mt65xx_lcm_list.c中的 #if defined(ILI9806) 可以进行预编译处理;
4、LCM驱动简要解析
LCM_DRIVER结构表示一个LCM对象,里边包含LCM各项参数;
LCM_DRIVER ili9806e_drv = { .name = "ili9806e_txd_dsi_cmd_sp13_lcm_drv", //设备名 .set_util_funcs = lcm_set_util_funcs, //获取LCM_DRIVER结构 .get_params = lcm_get_params, //获取lcm参数 .init = lcm_init, //lcm初始化函数 .suspend = lcm_suspend, //lcm挂起 .resume = lcm_resume, //lcm恢复 .compare_id = lcm_compare_id, //设备id匹配 };
以上函数接口是为MTK框架中的几个重要接口;
/* 获取设备的LCM_DRIVER结构 */
static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) { memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); } /* 获取lcm各个参数 */ static void lcm_get_params(LCM_PARAMS *params) { memset(params, 0, sizeof(LCM_PARAMS)); //先将LCM_PARAMS结构清空 params->type = LCM_TYPE_DSI; //lcm接口类型 params->width = FRAME_WIDTH; //lcm显示宽度 params->height = FRAME_HEIGHT; //lcm显示高度 /* 设置通信模式 */ // enable tearing-free params->dbi.te_mode = LCM_DBI_TE_MODE_DISABLED; params->dbi.te_edge_polarity = LCM_POLARITY_RISING; /* dsi分两种模式,一种是cmd模式,一种是video模式 */ #if (LCM_DSI_CMD_MODE) params->dsi.mode = CMD_MODE; #else params->dsi.mode = SYNC_PULSE_VDO_MODE; #endif /* 设置数据格式 */ // DSI /* Command mode setting */ params->dsi.LANE_NUM = LCM_TWO_LANE; //两通道MIPI //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; // Highly depends on LCD driver capability. // Not support in MT6573 params->dsi.packet_size = 256; // Video mode setting params->dsi.intermediat_buffer_num = 0; params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888; params->dsi.word_count = 480 * 3; /* 垂直参数设置 */ params->dsi.vertical_sync_active = 4; //垂直同步信号的宽度 params->dsi.vertical_backporch = 16;//10 //垂直同步信号的后沿 params->dsi.vertical_frontporch = 20;//8 //垂直同步信号的前沿 params->dsi.vertical_active_line = FRAME_HEIGHT; /* 水平参数设置 */ params->dsi.horizontal_sync_active = 10; //水平同步信号的宽度 params->dsi.horizontal_backporch = 50; //水平同步信号的后沿 params->dsi.horizontal_frontporch = 60; //水平同步信号的前沿 params->dsi.horizontal_active_pixel = FRAME_WIDTH; /* 时钟频率 */ params->dsi.PLL_CLOCK= 200; }
//复位引脚
#define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) //这里就会直接使用GPIO_LCD_RST硬引脚
//延时函数
#define UDELAY(n) (lcm_util.udelay(n))
#define MDELAY(n) (lcm_util.mdelay(n))
//读写寄存器等操作
#define write_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
#define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, bytes_nums)
#define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
#define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
/* 初始化参数及函数接口 */
static struct LCM_setting_table lcm_initialization_setting[] = { /* 数据格式:命令,数据个数,数据 */ //命令一般是对应寄存器地址 {0xFF, 5,{0xFF,0x98,0x06,0x04,0x01}}, {0x08, 1, {0x10}}, {0x21, 1, {0x01}}, {0x30, 1, {0x02}}, {0x31, 1, {0x02}}, {0x40, 1, {0x16}}, {0x41, 1, {0x22}}, ...... {0x53, 1, {0x1A}}, //10 {0xFF, 5,{0xFF,0x98,0x06,0x04,0x07}}, {0x17, 1, {0x12}}, //22 {0x02, 1, {0x77}}, {0xFF, 5,{0xFF,0x98,0x06,0x04,0x00}}, {0x35,1, {0x00}}, {0x36,1, {0x03}}, //翻转180度 {0x11, 1, {0x00}}, {REGFLAG_DELAY, 120, {}}, {0x29, 1, {0x00}}, {REGFLAG_DELAY, 50, {}}, {REGFLAG_END_OF_TABLE, 0x00, {}} //数据结束必须使用REGFLAG_END_OF_TABLE }; static void lcm_init(void) {
/* 复位 */ SET_RESET_PIN(1); MDELAY(10); SET_RESET_PIN(0); /* Third change Lava */ MDELAY(10);//10 SET_RESET_PIN(1); MDELAY(120); // 150 /* 初始化数据 */ push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1); }
static void lcm_suspend(void) { #ifdef BUILD_LK printf("%s, ALS/PS bbbbbbbbbbbbbbb \n", __func__); #else printk("%s, ALS/PS bbbbbbbbbbbbbb \n", __func__); #endif push_table(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1); SET_RESET_PIN(0); MDELAY(20);//10 SET_RESET_PIN(1); MDELAY(50); }
因为lcm驱动被映射到lk层,在lk层只能使用printf进行调试,但在kernel层中只能printk进行打印调试,所以可以使用宏进行BUILD_LK区分;
挂起的机制一般有两种:简单睡眠或深度睡眠;
简单睡眠:设备还处于工作状态,可以被唤醒,但是此时也会存在待机功耗等问题;
深度睡眠:设备处于休眠状态,基本处于不工作状态,因此无法被唤醒;
一般程序设计都是使用深度睡眠,在唤醒时进行重新初始化;
static void lcm_resume(void) { lcm_init(); //push_table(lcm_sleep_out_setting, sizeof(lcm_sleep_out_setting) / sizeof(struct LCM_setting_table), 1); }重新初始化设备
/* 设备id匹配 */
static unsigned int lcm_compare_id() { unsigned int array[4]; unsigned char buffer[4] = {0,0,0,0}; unsigned char id_high=0; unsigned char id_low=0; unsigned char id_low0=0; unsigned int id=0; /* 先进行复位操作 */ SET_RESET_PIN(1); MDELAY(10); SET_RESET_PIN(0); MDELAY(10); SET_RESET_PIN(1); MDELAY(200); //*************Enable CMD2 Page1 *******************// array[0]=0x00063902; array[1]=0x0698ffff; array[2]=0x00000104; dsi_set_cmdq(array, 3, 1); array[0] = 0x00043700; dsi_set_cmdq(array, 1, 1); MDELAY(10); read_reg_v2(0x00, buffer, 4); id_high = buffer[0]; //98 array[0] = 0x00043700; dsi_set_cmdq(array, 1, 1); MDELAY(10); read_reg_v2(0x01, buffer, 4); id_low = buffer[0]; //06 array[0] = 0x00043700; dsi_set_cmdq(array, 1, 1); MDELAY(10); read_reg_v2(0x02, buffer, 4); id_low0 = buffer[0]; //04 id = (id_high<<16) | (id_low<<8)|id_low0; #ifdef BUILD_LK printf("ILI9806e:id2=%x.\n",id); printf("ILI9806e:id4=%x.\n",id_high); printf("ILI9806e:id5=%x.\n",id_low); printf("ILI9806e:id5=%x.\n",id_low0); #else printk("ILI9806e:id=%x.\n",id); printk("ILI9806e:id_high=%x.\n",id_high); printk("ILI9806e:id_low=%x.\n",id_low); printk("ILI9806e:id_low=%x.\n",id_low0); #endif return (0x980604 == id) ? 1 : 0; }数据编写格式是遵循MIPI协议进行编写的
注:如果系统只配置一个lcm设备,lcm_compare_id接口不会调用,只有系统存在多个设备的是才会调用该接口进行匹配;
标签:
原文地址:http://blog.csdn.net/u010245383/article/details/50981877