http://blog.csdn.net/mcgrady_tracy/article/details/42418413
平台:mt65852 + Android 4.4 屏:HX8389B
那么首先来看的是如何配置lcd屏(在mtk中叫做lcm)。
1. ProjectConfig.mk中配置
- CUSTOM_LK_LCM = hx8389b_qhd_dsi_vdo
- CUSTOM_KERNEL_LCM = hx8389b_qhd_dsi_vdo
- LCM_HEIGHT = 960
- LCM_WIDTH = 540
- BOOT_LOGO = cu_qhd
2. 修改mt65xx_lcm_list.c
那么先在mediatek/custom/common/kernel/lcm目录中创建一个目录hx8389b_qhd_dsi_vdo(注意,目录的名字要和ProjectConfig.mk中的lcm配置相对应),然后在该目录下创建一个文件hx8389b_qhd_dsi_vdo.c,至于这个文件里面应该填些什么内容,我们稍后来看。
然后修改mt65xx_lcm_list.c,依照已有的格式在lcm_driver_list这个数组里面添加下面的内容:
- #if defined(HX8389B_QHD_DSI_VDO)
- &hx8389b_qhd_dsi_vdo_drv,
- #endif
- extern LCM_DRIVER hx8389b_qhd_dsi_vdo_drv;
3. 编写hx8389b_qhd_dsi_vdo.c
根据前面步骤可以看到,肯定需要一个hx8389b_qhd_dsi_vdo_drv这个结构,它的类型是LCM_DRIVER,来看一下应该怎么定义:
- LCM_DRIVER hx8389b_qhd_dsi_vdo_drv = {
- .name = "hx8389b_qhd_dsi_vdo",
- .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,
- };
那么hx8389b_qhd_dsi_vdo_drv这个结构是定义好了,那么接下来是要实现结构体中定义的接口函数了。
先来看lcm_set_util_funcs这个函数:
- static LCM_UTIL_FUNCS lcm_util;
- static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
- {
- memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
- }
再来看lcm_get_params。
lcm_get_params函数中主要是一些参数定义,例如屏的分辨率,屏的接口类型等等:
- #define FRAME_WIDTH 540
- #define FRAME_HEIGHT 960
- static void lcm_get_params(LCM_PARAMS *params)
- {
- memset(params, 0, sizeof(LCM_PARAMS));
- params->type = LCM_TYPE_DSI; /* lcm的接口类型 */
- params->width = FRAME_WIDTH; /* lcm分辨率 */
- params->height = FRAME_HEIGHT;
- params->dsi.mode = SYNC_PULSE_VDO_MODE; /* video mode */
- params->dsi.LANE_NUM = LCM_THREE_LANE; /* lanes */
- params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888; /* 数据格式 */
- params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
- params->dsi.vertical_sync_active = 0x02; /* video mode需要配置的一些参数 */
- params->dsi.vertical_backporch = 0x0e;
- params->dsi.vertical_frontporch = 0x09;
- params->dsi.vertical_active_line = FRAME_HEIGHT;
- params->dsi.horizontal_sync_active = 0x21;
- params->dsi.horizontal_backporch = 0x21;
- params->dsi.horizontal_frontporch = 0x15;
- params->dsi.horizontal_active_pixel = FRAME_WIDTH;
- params->dsi.PLL_CLOCK = 180; /* clock(MHz) */
- }
再来看lcm_init:
- #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))
- #define dsi_set_cmdq_V3(para_tbl, size, force_update) lcm_util.dsi_set_cmdq_V3(para_tbl, size, force_update)
- #define dsi_set_cmdq_V2(cmd, count ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppare, force_update)
- #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
- #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 LCM_setting_table_V3 lcm_initialization_setting[] = {
- {0x39, 0xF0, 5, {0x55, 0xAA, 0x52, 0x08, 0x03}},
- {0x39, 0x90, 9, {0x05, 0x14, 0x05, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00}},
- {0x39, 0x91, 9, {0x05, 0x14, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00}},
- {0x39, 0x92, 11, {0x40, 0x09, 0x0A, 0x0B, 0x0C, 0x00, 0x54, 0x00, 0x00, 0x05, 0x08}},
- {0x39, 0x94, 8, {0x00, 0x08, 0x05, 0x03, 0xCE, 0x03, 0xD0, 0x0C}},
- {0x39, 0x95, 16, {0x40, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x10, 0x00, 0x54, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08}},
- {0x39, 0x99, 2, {0x00, 0x00}},
- {0x39, 0x9A, 11, {0x80, 0x0D, 0x03, 0xD2, 0x03, 0xD4, 0x00, 0x00, 0x00, 0x00, 0x50}},
- {0x39, 0x9B, 6, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
- {0x39, 0x9C, 2, {0x00, 0x00}},
- {0x39, 0x9D, 8, {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00}},
- {0x39, 0x9E, 2, {0x00, 0x00}},
- {0x39, 0xA0, 10, {0x95, 0x14, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0B, 0x1F}},
- {0x39, 0xA1, 10, {0x1F, 0x1F, 0x09, 0x1F, 0x1F, 0x1F, 0x0F, 0x1F, 0x1F, 0x1F}},
- {0x39, 0xA2, 10, {0x0D, 0x1F, 0x01, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x05, 0x1F}},
- {0x39, 0xA3, 10, {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}},
- {0x39, 0xA4, 10, {0x1F, 0x04, 0x1F, 0x1F, 0x1F, 0x02, 0x1F, 0x00, 0x1F, 0x0C}},
- {0x39, 0xA5, 10, {0x1F, 0x1F, 0x1F, 0x0E, 0x1F, 0x1F, 0x1F, 0x08, 0x1F, 0x1F}},
- {0x39, 0xA6, 10, {0x1F, 0x0A, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x14, 0x15}},
- {0x39, 0xA7, 10, {0x14, 0x15, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0C, 0x1F}},
- {0x39, 0xA8, 10, {0x1F, 0x1F, 0x0E, 0x1F, 0x1F, 0x1F, 0x08, 0x1F, 0x1F, 0x1F}},
- {0x39, 0xA9, 10, {0x0A, 0x1F, 0x02, 0x1F, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x04}},
- {0x39, 0xAA, 10, {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}},
- {0x39, 0xAB, 10, {0x1F, 0x05, 0x1F, 0x1F, 0x1F, 0x01, 0x1F, 0x03, 0x1F, 0x0B}},
- {0x39, 0xAC, 10, {0x1F, 0x1F, 0x1F, 0x09, 0x1F, 0x1F, 0x1F, 0x0F, 0x1F, 0x1F}},
- {0x39, 0xAD, 10, {0x1F, 0x0D, 0x1F, 0x1F, 0x1F, 0x02, 0x1F, 0x1F, 0x15, 0x14}},
- {0x39, 0xF0, 5, {0x55, 0xAA, 0x52, 0x08, 0x00}},
- {0x15, 0xFC, 1, {0x00}},
- {0x39, 0xBC, 3, {0x00, 0x00, 0x00}},
- {0x39, 0xB8, 4, {0x01, 0x8F, 0xBF, 0x80}},
- {0x39, 0xF0, 5, {0x55, 0xAA, 0x52, 0x08, 0x01}},
- {0x39, 0xD1, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xD2, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xD3, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xD4, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xD5, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xD6, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xD7, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xD8, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xD9, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xDD, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xDE, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xDF, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xE0, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xE1, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xE2, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xE3, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xE4, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xE5, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xE6, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xE7, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xE8, 16, {0x00, 0x17, 0x00, 0x58, 0x00, 0x8D, 0x00, 0xB0, 0x00, 0xCA, 0x00, 0xF2, 0x01, 0x12, 0x01, 0x45}},
- {0x39, 0xE9, 16, {0x01, 0x6D, 0x01, 0xAC, 0x01, 0xDD, 0x02, 0x29, 0x02, 0x67, 0x02, 0x69, 0x02, 0xA3, 0x02, 0xE0}},
- {0x39, 0xEA, 16, {0x03, 0x05, 0x03, 0x34, 0x03, 0x53, 0x03, 0x7C, 0x03, 0x94, 0x03, 0xB7, 0x03, 0xC9, 0x03, 0xD9}},
- {0x39, 0xEB, 4, {0x03, 0xEE, 0x03, 0xFF}},
- {0x39, 0xB0, 3, {0x05, 0x05, 0x05}},
- {0x39, 0xB1, 3, {0x05, 0x05, 0x05}},
- {0x39, 0xB6, 3, {0x44, 0x44, 0x44}},
- {0x39, 0xB7, 3, {0x34, 0x34, 0x34}},
- {0x39, 0xB3, 3, {0x12, 0x12, 0x12}},
- {0x39, 0xB9, 3, {0x34, 0x34, 0x34}},
- {0x39, 0xB4, 3, {0x06, 0x06, 0x06}},
- {0x39, 0xBA, 3, {0x14, 0x14, 0x14}},
- {0x39, 0xBC, 3, {0x00, 0x98, 0x00}},
- {0x39, 0xBD, 3, {0x00, 0x98, 0x00}},
- {0x15, 0xBE, 1, {0x5A}},//60
- {0x39, 0xF0, 5, {0x55, 0xAA, 0x52, 0x08, 0x02}},
- {0x39, 0xF6, 2, {0xCA, 0x69}},
- {0x39, 0xFB, 3, {0x09, 0x03, 0x08}},
- {0x39, 0xF1, 3, {0x22, 0x22, 0x32}},
- {0x15, 0x35, 1, {0x00}},
- {0x05, 0x11,0,{0x00}},
- {REGFLAG_ESCAPE_ID, REGFLAG_DELAY_MS_V3, 200, {}},
- {0x05, 0x29,0,{0x00}},
- {REGFLAG_ESCAPE_ID, REGFLAG_DELAY_MS_V3, 10, {}},
- };
- static void lcm_init(void)
- {
- SET_RESET_PIN(0);
- MDELAY(20);
- SET_RESET_PIN(1);
- MDELAY(120);
- dsi_set_cmdq_V3(lcm_initialization_setting, sizeof(lcm_initialization_setting)/sizeof(lcm_initialization_setting[0]), 1);
- }
mipi dsi协议中主要有两种packet,long packet和short packet。short packet长度为固定的4个字节,而long packet长度为6~65541(4+(0~65535)+2)字节。
short packet格式如下:
long packet格式如下:
不管是long packet还是short packet,都有个DATA ID字段,高两位我们先忽略,而低六位为Data Type,mipi dsi协议中有专门定义,这里暂时用到的有:
0x05 Short WRITE,无参数 0x15 Short WRITE,带一个参数 0x39 Long WRITE
详细的Data Type可以参见mipi dsi手册。
我们看在lcm_initialization_setting数组中,第一个值就是这里的Data Type,而第二个值则是hx8389b寄存器的地址,而第三个参数则是参数的个数,而最后才是参数值。
hx8389b的datasheet也给出了两个例子,例如:
05h CMD 0 ECC 05h 29h 00 1Ch (display on(29h)) 15h CMD Par ECC 15h 36h 08h 11h (MADCTL(36h)-BGR bit=1)我们可以看出lcm_init同它的名字一样,主要是对屏做初始化操作。
再来看lcm_suspend和lcm_resume。
- static void lcm_suspend(void)
- {
- unsigned int data_array[16];
- data_array[0] = 0x00100500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(120);
- SET_RESET_PIN(1);
- SET_RESET_PIN(0);
- MDELAY(20);
- SET_RESET_PIN(1);
- MDELAY(120);
- }
- static void lcm_resume(void)
- {
- lcm_init();
- }
如果是short packet,那么数组的第一个元素定义如下:
bits 8~15 16~23 24~31 DATA_ID DATA_0 DATA_1
所以,前面data_array[0] = 0x00100500对应的是一个不带参数的short packet,寄存器地址是0x10,下发的指令意思是进入sleep模式(可以参见hx8389b的数据手册)。
如果是long packet,那么数组的第一个元素定义如下:
bits 8~15 16~23 DATA_ID DATA_0
注意,在long packet中,DATA_0表示的是Word Count的低8位。
最后来看那个lcm_compare_id函数。
compare_id函数对于lcm驱动来说不是必须的,但最好加上。这个函数主要是用于兼容lcm时,lcm核心会调用该函数来匹配lcm驱动和屏。
- #define LCM_ID_HX8389B 0x89
- static unsigned int lcm_compare_id(void)
- {
- unsigned int id = 0;
- unsigned char buffer[2];
- unsigned int array[16];
- SET_RESET_PIN(1);
- SET_RESET_PIN(0);
- MDELAY(1);
- SET_RESET_PIN(1);
- MDELAY(10);
- array[0] = 0x00023700;
- dsi_set_cmdq(array, 1, 1);
- MDELAY(10);
- read_reg_v2(0x04, buffer, 2);
- id = buffer[1];
- return (id == LCM_ID_HX8389B) ? 1 : 0;
- }
0x37 Set Maximum Return Packet Size 0x06 DCS READ, no parameters
read_reg_v2第一个参数为读寄存器的地址。
参考文档:
1. MIPI_DSI_Specification_V1.02.00.pdf
2. HX8389-B_DS_Temporary_General_v00_20120109.pdf
3. MT6582_LCM_Porting_Guide_DSI_V1.0.pptx.pdf
// 2016-03-17 add
Command and Video Modes
兼容MIPI DSI协议的外设都支持Command Mode和Video Mode两种操作模式,具体使用哪一种操作模式由具体的外设架构决定,那么这两种操作模式它们有什么区别呢。
Video Mode:
这种操作模式同传统的RGB接口类似,主控制器需要实时的往显示屏上刷新像素数据,因为数据流一般比较大,这种模式只能工作在高速率模式下。这种模式是不需要带有显存的。
Video Mode同样也包含一些简单的命令操作,例如屏的初始化、屏的打开、关闭等等,这个时候是工作在低速模式下的。
Video Mode主要又有三种模式:
1. Non-burst Mode Sync pulses
2. Non-burst Mode Sync event
3. Burst mode
Command Mode:
MIPI主控制器通过命令集往显示器发送像素数据流,所以这种模式必须要有一个显存(frame buffer)用来存储像素数据。
参考:MIPI_DSI_Specification_V1.02.00.pdf
http://www.electronicproducts.com/Analog_Mixed_Signal_ICs/Communications_Interface/MIPI_display_standards_for_mobile_Internet_devices.aspx
附:HX8389B Datasheet下载地址:http://download.csdn.net/detail/mcgrady_tracy/8327585