MTK android lcm调试

参考MTK 文档LCM_Customer_document_MT6575.pdf


The following shows the steps to add a new LCM driver: 

(1)  Create LCM driver folder $LCM in alps/mediatek/custom/common/kernel/lcm/

(2)  Create LCM driver source file $LCM.c in alps/mediatek/custom/common/kernel/lcm/$LCM

(3)  Implement LCM driver and export lcm_driver_list/lcm_count variables. 

                    


Adaptive LCM Support 
At first you should add you new lcm driver as listed in the previous section, and then add the 
adaptive support: 
1.  Modify the adaptive lcm driver common file:  
alps/mediatek/custom/common/kernel/lcm/mt65xx_lcm_list.c

2.  Add the new LCM driver global variables as shown in the figure below: 

                

3.  [VERY IMPORTANT] Please delete the unused LCM driver folder in the customization folder, 
such as shown in the figure below: 

              MTK android lcm调试_第1张图片


4. But what if I didn’t delete the folders un-usable? The code size will increase, because the 
other LCM drivers will be compiled into codebase too; And if your project doesn’t define 
GPIO usage for serial interface, there will be build error.

5.  Modify the project makefile alps/mediate/config/(project)/ProjetConfig.mk 
Modify CUSTOM_KERNEL_LCM=mt65xx 
Modify CUSTOM_UBOOT_LCM=mt65xx



Case Study – DBI Interface LCM Driver Porting 

In this chapter, we’ll go through a real case study of DBI LCM driver porting. 

LCM specifications: 
  LCM Drive IC: hx8369 
  Interface: 24-bit 80 system bus interface 
  LCD size: 480*800 
  
1.  Create LCM driver folder and LCM driver source file 
alps/mediatek/custom/common/kernel/lcm/hx8369/lcm_dr.c 

2.  Modify the project makefile alps/mtk/make/$(project).mak 
Add CUSTOM_KERNEL_LCM= hx8369 
Add CUSTOM_UBOOT_LCM= hx8369 

3.  Fill the LCM parameters 
A.  Configure the basic information according to the HW connection, LCM type and LCM size: 

                 MTK android lcm调试_第2张图片

MT6575 LCD IO selection is as shown in following table. LCD data pin can share between DPI and NAND data pin 

            MTK android lcm调试_第3张图片


For example, we use 24bits DBI interface LCM, and connect LCM data pin to MT6575 baseband 
Pin DPIR[7:0], DPIG[7:0], DPIB[7:0]. So we must set io_select_mode to be 1; if connect LCM data 
pin to Nand IF, we must set io_select_mode to be 0


B.  Configure data format according to the RGB data pin assignment of the LCM datasheet 

            MTK android lcm调试_第4张图片


C.  Configure LCM waveform timing according to the requirement specified in the LCM datasheet

              MTK android lcm调试_第5张图片


Note: MT6575 LCD controller clock frequency is 130MHz, so clock cycle time is 1/130MHz = 7.69ns


4.  Implement LCM init function 

According the init process specified in LCM datasheet, pull down/up the reset pin, delay and set 
LCM init register settings. 


5.  Implement LCM update function 
Send the block update commands to LCM 

6.  Implement LCM suspend/resume functions 
Send suspend/resume commands to LCM


7. Rebuild uboot and kernel 
In the root directory: 
./mk $(project) gen_cust 
./mk $(project) remake uboot/kernel 
./mk $(project) bootimage 


参考代码:

[cpp]  view plain copy
  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2008
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/ 
  35.  
  36. #include <linux/string.h> 
  37.  
  38. #include "lcm_drv.h" 
  39.  
  40. //#include <linux/kernel.h> //for printk() 
  41.  
  42. //extern void printf(const char* fmt, ...); 
  43.  
  44. #ifdef BUILD_UBOOT 
  45. #include <asm/arch/mt6575_gpio.h> 
  46. #define print(x...) printf(x) 
  47. #else 
  48. #include <mach/mt6575_gpio.h> 
  49. #define print(x...) printk(x) 
  50. #endif 
  51.  
  52.  
  53. //libin modify for M1-4 on 20120726 
  54. #define GPIO_LCD_RST   18 //GPIO18 
  55. #define  GPIO_MODE_00  0 
  56. #define GPIO_DIR_OUT   1 
  57. #define GPIO_OUT_ONE  1 
  58. #define GPIO_OUT_ZERO  0 
  59. extern s32 mt_set_gpio_mode(u32 u4Pin, u32 u4Mode); 
  60. extern s32 mt_set_gpio_out(u32 u4Pin, u32 u4PinOut); 
  61. extern s32 mt_set_gpio_dir(u32 u4Pin, u32 u4Dir); 
  62.  
  63. // --------------------------------------------------------------------------- 
  64. //  Local Constants 
  65. // --------------------------------------------------------------------------- 
  66.  
  67. #define FRAME_WIDTH  (320) 
  68. #define FRAME_HEIGHT (480) 
  69.  
  70. // --------------------------------------------------------------------------- 
  71. //  Local Variables 
  72. // --------------------------------------------------------------------------- 
  73.  
  74. static LCM_UTIL_FUNCS lcm_util = {0}; 
  75.  
  76. #define SET_RESET_PIN(v)    (lcm_util.set_reset_pin((v))) 
  77.  
  78. #define UDELAY(n) (lcm_util.udelay(n)) 
  79. #define MDELAY(n) (lcm_util.mdelay(n)) 
  80.  
  81.  
  82. // --------------------------------------------------------------------------- 
  83. //  Local Functions 
  84. // --------------------------------------------------------------------------- 
  85.  
  86. static __inline unsigned int HIGH_BYTE(unsigned int val) 
  87.     return (val >> 8) & 0xFF; 
  88.  
  89. static __inline unsigned int LOW_BYTE(unsigned int val) 
  90.     return (val & 0xFF); 
  91.  
  92. static __inline void send_ctrl_cmd(unsigned int cmd) 
  93. //MDELAY(5); 
  94. //mt_set_gpio_out(16, GPIO_OUT_ZERO);     
  95.     lcm_util.send_cmd(cmd); 
  96. //  mt_set_gpio_out(16, GPIO_OUT_ONE);  
  97.  
  98. static __inline void send_data_cmd(unsigned int data) 
  99. //MDELAY(5); 
  100. //mt_set_gpio_out(16, GPIO_OUT_ZERO);     
  101.     lcm_util.send_data(data); 
  102. //  mt_set_gpio_out(16, GPIO_OUT_ONE);  
  103.  
  104. static __inline unsigned int read_data_cmd() 
  105.     return lcm_util.read_data(); 
  106.  
  107. static __inline void set_lcm_register(unsigned int regIndex, 
  108.                                       unsigned int regData) 
  109.     send_ctrl_cmd(regIndex); 
  110.     send_data_cmd(regData); 
  111.  
  112.  
  113. static void init_lcm_registers(void
  114. send_ctrl_cmd(0xF1); 
  115. send_data_cmd(0x36);  
  116. send_data_cmd(0x04);  
  117. send_data_cmd(0x00);  
  118. send_data_cmd(0x3C); 
  119. send_data_cmd(0x0F); 
  120. send_data_cmd(0x8F); 
  121.  
  122. send_ctrl_cmd(0xf2); 
  123. send_data_cmd(0x18);  
  124. send_data_cmd(0xa3);  
  125. send_data_cmd(0x12);  
  126. send_data_cmd(0x02);  
  127. send_data_cmd(0xb2);  
  128. send_data_cmd(0x12);  
  129. send_data_cmd(0xff);  
  130. send_data_cmd(0x10);  
  131. send_data_cmd(0x00);  
  132.  
  133. send_ctrl_cmd(0xf8);  
  134. send_data_cmd(0x21);  
  135. send_data_cmd(0x04);  
  136.  
  137. send_ctrl_cmd(0xf9);  
  138. send_data_cmd(0x00);  
  139. send_data_cmd(0x08);  
  140.  
  141. send_ctrl_cmd(0xC0);  
  142. send_data_cmd(0x0F);  
  143. send_data_cmd(0x0F);  
  144.  
  145. send_ctrl_cmd(0xc1);  
  146. send_data_cmd(0x42);  
  147.  
  148. send_ctrl_cmd(0xC2);  
  149. send_data_cmd(0x22);  
  150.  
  151. send_ctrl_cmd(0xc5);  
  152. send_data_cmd(0x00);  
  153. send_data_cmd(0x08);  
  154. send_data_cmd(0x80);  
  155.  
  156. send_ctrl_cmd(0xb1);  
  157. send_data_cmd(0xB0);  
  158. send_data_cmd(0x11);  
  159.  
  160. send_ctrl_cmd(0xb4);  
  161. send_data_cmd(0x02);  
  162.  
  163. send_ctrl_cmd(0xb6);  
  164. send_data_cmd(0x02);  
  165. send_data_cmd(0x02); //cpu?02 
  166.  
  167. send_ctrl_cmd(0xb7);  
  168. send_data_cmd(0xC6);  
  169.  
  170. send_ctrl_cmd(0x3a);  
  171. send_data_cmd(0x66/*0x55*/);//16bit ?55  18bit  ?66 
  172.  
  173. send_ctrl_cmd(0x35);  
  174. send_data_cmd(0x00);  
  175.  
  176. send_ctrl_cmd(0x44);  
  177. send_data_cmd(0x00); 
  178. send_data_cmd(0x5f); 
  179.  
  180. send_ctrl_cmd(0x36);  
  181. send_data_cmd(0x08); // 0xc8 
  182.  
  183. send_ctrl_cmd(0x2a);  
  184. send_data_cmd(0x00); 
  185. send_data_cmd(0x00); 
  186. send_data_cmd(0x01);  
  187. send_data_cmd(0x3f); 
  188.  
  189. send_ctrl_cmd(0x2b); 
  190. send_data_cmd(0x00);  
  191. send_data_cmd(0x00);  
  192. send_data_cmd(0x01);  
  193. send_data_cmd(0xdf);  
  194.  
  195. send_ctrl_cmd(0xe0);  
  196. send_data_cmd(0x00);  
  197. send_data_cmd(0x1D);  
  198. send_data_cmd(0x19);  
  199. send_data_cmd(0x0c);  
  200. send_data_cmd(0x0f);  
  201. send_data_cmd(0x0A);          
  202. send_data_cmd(0x45);  
  203. send_data_cmd(0x95);  
  204. send_data_cmd(0x38);  
  205. send_data_cmd(0x0a);  
  206. send_data_cmd(0x12); 
  207. send_data_cmd(0x03);  
  208. send_data_cmd(0x09);  
  209. send_data_cmd(0x06);  
  210. send_data_cmd(0x00);  
  211.  
  212. send_ctrl_cmd(0xe1);  
  213. send_data_cmd(0x0f);  
  214. send_data_cmd(0x37);  
  215. send_data_cmd(0x35);  
  216. send_data_cmd(0x0C);  
  217. send_data_cmd(0x0d);  
  218. send_data_cmd(0x04);  
  219. send_data_cmd(0x48);  
  220. send_data_cmd(0x43);  
  221. send_data_cmd(0x35);  
  222. send_data_cmd(0x04);  
  223. send_data_cmd(0x0D);  
  224. send_data_cmd(0x02);  
  225. send_data_cmd(0x1C);  
  226. send_data_cmd(0x18);  
  227. send_data_cmd(0x0F);  
  228.  
  229. send_ctrl_cmd(0x11); 
  230. MDELAY(120);  
  231. send_ctrl_cmd(0x29);  
  232. send_ctrl_cmd(0x2c);  
  233. MDELAY(10);  
  234.  
  235.  
  236. // --------------------------------------------------------------------------- 
  237. //  LCM Driver Implementations 
  238. // --------------------------------------------------------------------------- 
  239.  
  240. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) 
  241.     memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); 
  242.  
  243.  
  244. static void lcm_get_params(LCM_PARAMS *params) 
  245.     memset(params, 0, sizeof(LCM_PARAMS)); 
  246.  
  247.     params->type   = LCM_TYPE_DBI; 
  248.     params->ctrl   = LCM_CTRL_PARALLEL_DBI; 
  249.     params->width  = FRAME_WIDTH; 
  250.     params->height = FRAME_HEIGHT; 
  251.     params->io_select_mode = 1; 
  252.  
  253.     params->dbi.port                    = 0; // 1; 
  254.    //params->dbi.clock_freq              = LCM_DBI_CLOCK_FREQ_104M;  //aa 
  255.     params->dbi.data_width              = LCM_DBI_DATA_WIDTH_18BITS;//LCM_DBI_DATA_WIDTH_16BITS; 
  256.     params->dbi.data_format.color_order = LCM_COLOR_ORDER_RGB; 
  257.     params->dbi.data_format.trans_seq   = LCM_DBI_TRANS_SEQ_MSB_FIRST; 
  258.     params->dbi.data_format.padding     = LCM_DBI_PADDING_ON_LSB; //LCM_DBI_PADDING_ON_LSB; //bb 
  259.     params->dbi.data_format.format      = LCM_DBI_FORMAT_RGB666; //LCM_DBI_FORMAT_RGB565; 
  260.     params->dbi.data_format.width       = LCM_DBI_DATA_WIDTH_18BITS; //LCM_DBI_DATA_WIDTH_16BITS; 
  261.     params->dbi.cpu_write_bits          = LCM_DBI_CPU_WRITE_32_BITS; //LCM_DBI_CPU_WRITE_16_BITS; 
  262.     params->dbi.io_driving_current      = LCM_DRIVING_CURRENT_6575_8MA ;  // 0; 
  263.  
  264.   /* params->dbi.parallel.write_setup    = 1;
  265.     params->dbi.parallel.write_hold     = 1;
  266.     params->dbi.parallel.write_wait     = 9; // 3;
  267.     params->dbi.parallel.read_setup     = 1;
  268.     params->dbi.parallel.read_latency   = 31;
  269.     params->dbi.parallel.wait_period    = 2;*/ 
  270.  
  271.     params->dbi.parallel.write_setup    = 2;  
  272.     params->dbi.parallel.write_hold     = 2;  
  273.     params->dbi.parallel.write_wait     = 15;  
  274.     params->dbi.parallel.read_setup     = 1;  
  275.     params->dbi.parallel.read_latency   = 31;  
  276.     params->dbi.parallel.wait_period    = 2;  
  277.      params->dbi.parallel.cs_high_width = 0; 
  278.  
  279.  
  280.     // enable tearing-free 
  281.   //  params->dbi.te_mode                 = LCM_DBI_TE_MODE_VSYNC_ONLY; 
  282.    // params->dbi.te_edge_polarity        = LCM_POLARITY_FALLING; 
  283.      
  284.    /* params->dbi.te_mode                 = LCM_DBI_TE_MODE_VSYNC_OR_HSYNC;
  285.     params->dbi.te_edge_polarity        = LCM_POLARITY_RISING;
  286.     params->dbi.te_hs_delay_cnt         = 50;
  287.     params->dbi.te_vs_width_cnt         = 277;
  288.     params->dbi.te_vs_width_cnt_div     = LCM_DBI_TE_VS_WIDTH_CNT_DIV_16;*/ 
  289.  
  290.  
  291.  
  292. #define GPIO_LCD_RST   18 //GPIO18 
  293. #define  GPIO_MODE_00  0 
  294. #define GPIO_DIR_OUT   1 
  295. #define GPIO_OUT_ONE  1 
  296. #define GPIO_OUT_ZERO  0 
  297. extern s32 mt_set_gpio_mode(u32 u4Pin, u32 u4Mode); 
  298. extern s32 mt_set_gpio_out(u32 u4Pin, u32 u4PinOut); 
  299. extern s32 mt_set_gpio_dir(u32 u4Pin, u32 u4Dir); 
  300. static void lcm_init(void
  301.    /* SET_RESET_PIN(0);
  302.     MDELAY(200);
  303.     SET_RESET_PIN(1);
  304.     MDELAY(400);*/ 
  305.      
  306.      // SET_RESET_PIN(1);     
  307.    mt_set_gpio_mode(GPIO_LCD_RST,GPIO_MODE_00); 
  308.    mt_set_gpio_dir(GPIO_LCD_RST,GPIO_DIR_OUT); 
  309.    mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ONE); 
  310.     MDELAY(1);  
  311.     //SET_RESET_PIN(0);  
  312.     mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ZERO); 
  313.     MDELAY(10);  
  314.     //SET_RESET_PIN(1);  
  315.     mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ONE); 
  316.     MDELAY(100);  
  317.  
  318.  
  319.     init_lcm_registers(); 
  320.  
  321.  
  322. static void lcm_suspend(void
  323.     send_ctrl_cmd(0x28); 
  324.     MDELAY(20);  
  325. send_ctrl_cmd(0x10);  
  326. MDELAY(100);  
  327.  
  328.  
  329. static void lcm_resume(void
  330. send_ctrl_cmd(0x11);  
  331. MDELAY(100);  
  332. send_ctrl_cmd(0x29); 
  333. //MDELAY(100);  
  334. /*
  335.     send_ctrl_cmd(0x29);
  336.     MDELAY(120);
  337. send_ctrl_cmd(0x11);
  338. MDELAY(120); */ 
  339.  
  340.  
  341. static void lcm_update(unsigned int x, unsigned int y, 
  342.                        unsigned int width, unsigned int height) 
  343.     unsigned int x0 = x; 
  344.     unsigned int y0 = y; 
  345.     unsigned int x1 = x0 + width - 1; 
  346.     unsigned int y1 = y0 + height - 1; 
  347.  
  348. print( "[LCM] *********************ili9486 lcm_update*******************\n\r"); 
  349.   
  350.     send_ctrl_cmd(0x2A); 
  351.     send_data_cmd(HIGH_BYTE(x0)); 
  352.     send_data_cmd(LOW_BYTE(x0)); 
  353.     send_data_cmd(HIGH_BYTE(x1)); 
  354.     send_data_cmd(LOW_BYTE(x1)); 
  355.  
  356.     send_ctrl_cmd(0x2B); 
  357.     send_data_cmd(HIGH_BYTE(y0)); 
  358.     send_data_cmd(LOW_BYTE(y0)); 
  359.     send_data_cmd(HIGH_BYTE(y1)); 
  360.     send_data_cmd(LOW_BYTE(y1)); 
  361.  
  362.     // Write To GRAM 
  363.     send_ctrl_cmd(0x2C); 
  364.  
  365. static unsigned int lcm_compare_id(void
  366.     return 1; 
  367. // --------------------------------------------------------------------------- 
  368. //  Get LCM Driver Hooks 
  369. // --------------------------------------------------------------------------- 
  370. LCM_DRIVER ili9486_lcm_drv =  
  371.     .name           = "ili9486"
  372.     .set_util_funcs = lcm_set_util_funcs, 
  373.     .get_params     = lcm_get_params, 
  374.     .init           = lcm_init, 
  375.     .suspend        = lcm_suspend, 
  376.     .resume         = lcm_resume, 
  377.     .update         = lcm_update, 
  378.     .compare_id     = lcm_compare_id 
  379. };

注意事项

1.调试屏幕主要的工作是初始化和时序设置

2.编译的时候,仅仅使用./mk r ub k 是不够的,还需要运行./mk bootimage命令

3.可能是更改了gpio口中LRSTB的原因导致reset失败,代码中通过以下代码手动设置reset信号

[cpp]  view plain copy
  1. static void lcm_init(void
  2. {  
  3.          // SET_RESET_PIN(1);     
  4.    mt_set_gpio_mode(GPIO_LCD_RST,GPIO_MODE_00); 
  5.    mt_set_gpio_dir(GPIO_LCD_RST,GPIO_DIR_OUT); 
  6.    mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ONE); 
  7.     MDELAY(1);  
  8.     //SET_RESET_PIN(0);  
  9.     mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ZERO); 
  10.     MDELAY(10);  
  11.     //SET_RESET_PIN(1);  
  12.     mt_set_gpio_out(GPIO_LCD_RST,GPIO_OUT_ONE); 
  13.     MDELAY(100);  
  14.  
  15. ... 

你可能感兴趣的:(MTK android lcm调试)