Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.28 KB | None | 0 0
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/string.h>
  4. #include <linux/wait.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/gpio.h>
  7. #include <linux/pinctrl/consumer.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/gpio.h>
  10. #include <asm-generic/gpio.h>
  11. #include <linux/fs.h>
  12. #include <linux/slab.h>
  13. #include <linux/init.h>
  14. #include <linux/list.h>
  15. #include <linux/i2c.h>
  16. #include <linux/irq.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/platform_device.h>
  21. #include <pinctrl-mtk-common.h>
  22.  
  23. #include "lcm_drv.h"
  24. #include "ddp_irq.h"
  25.  
  26.  
  27.  
  28. #ifndef TRUE
  29. #define TRUE 1
  30. #endif
  31.  
  32. #ifndef FALSE
  33. #define FALSE 0
  34. #endif
  35.  
  36. #define GPIO_MODE_00 0
  37. #define GPIO_DIR_OUT 1
  38. #define GPIO_OUT_ONE 1
  39. #define GPIO_OUT_ZERO 0
  40.  
  41. #define TPS_I2C_BUSNUM 1//I2C_I2C_LCD_BIAS_CHANNEL//for I2C channel 0//sophia
  42. #define I2C_ID_NAME "tps65132"
  43. #define TPS_ADDR 0x3E
  44. /*****************************************************************************
  45. * GLobal Variable
  46. *****************************************************************************/
  47.  
  48. static struct i2c_board_info __initdata tps65132_board_info = {I2C_BOARD_INFO(I2C_ID_NAME, TPS_ADDR)};
  49. static struct i2c_client *tps65132_i2c_client = NULL;
  50.  
  51.  
  52. /*****************************************************************************
  53. * Function Prototype
  54. *****************************************************************************/
  55. static int tps65132_probe(struct i2c_client *client, const struct i2c_device_id *id);
  56. static int tps65132_remove(struct i2c_client *client);
  57. /*****************************************************************************
  58. * Data Structure
  59. *****************************************************************************/
  60.  
  61. struct tps65132_dev {
  62. struct i2c_client *client;
  63. };
  64.  
  65. static const struct i2c_device_id tps65132_id[] = {
  66. {I2C_ID_NAME, 0},
  67. {}
  68. };
  69.  
  70. //#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36))
  71. //static struct i2c_client_address_data addr_data = { .forces = forces,};
  72. //#endif
  73. static struct i2c_driver tps65132_iic_driver = {
  74. .id_table = tps65132_id,
  75. .probe = tps65132_probe,
  76. .remove = tps65132_remove,
  77. //.detect = mt6605_detect,
  78. .driver = {
  79. .owner = THIS_MODULE,
  80. .name = "tps65132",
  81. },
  82. };
  83. /*****************************************************************************
  84. * Extern Area
  85. *****************************************************************************/
  86.  
  87.  
  88.  
  89. /*****************************************************************************
  90. * Function
  91. *****************************************************************************/
  92. static int tps65132_probe(struct i2c_client *client, const struct i2c_device_id *id)
  93. {
  94. printk( "tps65132_iic_probe\n");
  95. printk("TPS: info==>name=%s addr=0x%x\n",client->name,client->addr);
  96. tps65132_i2c_client = client;
  97. return 0;
  98. }
  99.  
  100.  
  101. static int tps65132_remove(struct i2c_client *client)
  102. {
  103. printk( "tps65132_remove\n");
  104. tps65132_i2c_client = NULL;
  105. i2c_unregister_device(client);
  106. return 0;
  107. }
  108.  
  109.  
  110. int tps65132_write_bytes(unsigned char addr, unsigned char value)
  111. {
  112. int ret = 0;
  113. struct i2c_client *client = tps65132_i2c_client;
  114. char write_data[2]={0};
  115. write_data[0]= addr;
  116. write_data[1] = value;
  117. ret=i2c_master_send(client, write_data, 2);
  118. if(ret<0)
  119. printk("tps65132 write data fail !!\n");
  120. return ret ;
  121. }
  122. EXPORT_SYMBOL_GPL(tps65132_write_bytes);
  123.  
  124.  
  125.  
  126. /*
  127. * module load/unload record keeping
  128. */
  129.  
  130. static int __init tps65132_iic_init(void)
  131. {
  132. printk( "tps65132_iic_init\n");
  133. i2c_register_board_info(TPS_I2C_BUSNUM, &tps65132_board_info, 1);
  134. printk( "tps65132_iic_init2\n");
  135. i2c_add_driver(&tps65132_iic_driver);
  136. printk( "tps65132_iic_init success\n");
  137. return 0;
  138. }
  139.  
  140. static void __exit tps65132_iic_exit(void)
  141. {
  142. printk( "tps65132_iic_exit\n");
  143. i2c_del_driver(&tps65132_iic_driver);
  144. }
  145.  
  146.  
  147. module_init(tps65132_iic_init);
  148. module_exit(tps65132_iic_exit);
  149.  
  150. MODULE_AUTHOR("Xiaokuan Shi");
  151. MODULE_DESCRIPTION("MTK TPS65132 I2C Driver");
  152. MODULE_LICENSE("GPL");
  153.  
  154. /* --------------------------------------------------------------------------- */
  155. /* Local Constants */
  156. /* --------------------------------------------------------------------------- */
  157.  
  158. #define FRAME_WIDTH (720)
  159. #define FRAME_HEIGHT (1280)
  160.  
  161. #define GPIO_LCD_ENN (0x8000003F) // GPIO63
  162. #define GPIO_LCD_ENP (0x80000040) // GPIO64
  163.  
  164. /* --------------------------------------------------------------------------- */
  165. /* Local Variables */
  166. /* --------------------------------------------------------------------------- */
  167.  
  168. static LCM_UTIL_FUNCS lcm_util = { 0 };
  169.  
  170. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  171. #define UDELAY(n) (lcm_util.udelay(n))
  172. #define MDELAY(n) (lcm_util.mdelay(n))
  173.  
  174. #define REGFLAG_DELAY 0XFFE
  175. #define REGFLAG_END_OF_TABLE 0x1FF // END OF REGISTERS MARKER
  176.  
  177.  
  178. /* --------------------------------------------------------------------------- */
  179. /* Local Functions */
  180. /* --------------------------------------------------------------------------- */
  181. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  182. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  183. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  184. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  185. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  186. #define lcm_set_gpio_out(gpio, value) lcm_util.set_gpio_out(gpio, value)
  187. #ifndef BUILD_LK
  188. extern atomic_t ESDCheck_byCPU;
  189. #endif
  190.  
  191. struct LCM_setting_table {
  192. unsigned cmd;
  193. unsigned char count;
  194. unsigned char para_list[64];
  195. };
  196.  
  197.  
  198. static struct LCM_setting_table lcm_initialization_setting[] = {
  199. {0xFF,3,{0x98,0x81,0x03}},
  200. {0x01,1,{0x00}},
  201. {0x02,1,{0x00}},
  202. {0x03,1,{0x53}},
  203. {0x04,1,{0x13}},
  204. {0x05,1,{0x13}},
  205. {0x06,1,{0x06}},
  206. {0x07,1,{0x00}},
  207. {0x08,1,{0x04}},
  208. {0x09,1,{0x00}},
  209. {0x0a,1,{0x00}},
  210. {0x0b,1,{0x00}},
  211. {0x0C,1,{0x00}},
  212. {0x0D,1,{0x00}},
  213. {0x0E,1,{0x00}},
  214. {0x0f,1,{0x00}},
  215. {0x10,1,{0x00}},
  216. {0x11,1,{0x00}},
  217. {0x12,1,{0x00}},
  218. {0x13,1,{0x00}},
  219. {0x14,1,{0x00}},
  220. {0x15,1,{0x00}},
  221. {0x16,1,{0x00}},
  222. {0x17,1,{0x00}},
  223. {0x18,1,{0x00}},
  224. {0x19,1,{0x00}},
  225. {0x1A,1,{0x00}},
  226. {0x1B,1,{0x00}},
  227. {0x1C,1,{0x00}},
  228. {0x1D,1,{0x00}},
  229. {0x1E,1,{0xC0}},
  230. {0x1F,1,{0x80}},
  231. {0x20,1,{0x04}},
  232. {0x21,1,{0x0B}},
  233. {0x22,1,{0x00}},
  234. {0x23,1,{0x00}},
  235. {0x24,1,{0x00}},
  236. {0x25,1,{0x00}},
  237. {0x26,1,{0x00}},
  238. {0x27,1,{0x00}},
  239. {0x28,1,{0x55}},
  240. {0x29,1,{0x03}},
  241. {0x2A,1,{0x00}},
  242. {0x2B,1,{0x00}},
  243. {0x2C,1,{0x00}},
  244. {0x2D,1,{0x00}},
  245. {0x2E,1,{0x00}},
  246. {0x2F,1,{0x00}},
  247. {0x30,1,{0x00}},
  248. {0x31,1,{0x00}},
  249. {0x32,1,{0x00}},
  250. {0x33,1,{0x00}},
  251. {0x34,1,{0x04}},
  252. {0x35,1,{0x05}},
  253. {0x36,1,{0x05}},
  254. {0x37,1,{0x00}},
  255. {0x38,1,{0x3C}},
  256. {0x39,1,{0x00}},
  257. {0x3A,1,{0x40}},
  258. {0x3B,1,{0x40}},
  259. {0x3C,1,{0x00}},
  260. {0x3D,1,{0x00}},
  261. {0x3E,1,{0x00}},
  262. {0x3F,1,{0x00}},
  263. {0x40,1,{0x00}},
  264. {0x41,1,{0x00}},
  265. {0x42,1,{0x00}},
  266. {0x43,1,{0x00}},
  267. {0x44,1,{0x00}},
  268. {0x50,1,{0x01}},
  269. {0x51,1,{0x23}},
  270. {0x52,1,{0x45}},
  271. {0x53,1,{0x67}},
  272. {0x54,1,{0x89}},
  273. {0x55,1,{0xAB}},
  274. {0x56,1,{0x01}},
  275. {0x57,1,{0x23}},
  276. {0x58,1,{0x45}},
  277. {0x59,1,{0x67}},
  278. {0x5A,1,{0x89}},
  279. {0x5B,1,{0xAB}},
  280. {0x5C,1,{0xCD}},
  281. {0x5D,1,{0xEF}},
  282. {0x5E,1,{0x01}},
  283. {0x5F,1,{0x14}},
  284. {0x60,1,{0x15}},
  285. {0x61,1,{0x0C}},
  286. {0x62,1,{0x0D}},
  287. {0x63,1,{0x0E}},
  288. {0x64,1,{0x0F}},
  289. {0x65,1,{0x10}},
  290. {0x66,1,{0x11}},
  291. {0x67,1,{0x08}},
  292. {0x68,1,{0x02}},
  293. {0x69,1,{0x0A}},
  294. {0x6A,1,{0x02}},
  295. {0x6B,1,{0x02}},
  296. {0x6C,1,{0x02}},
  297. {0x6D,1,{0x02}},
  298. {0x6E,1,{0x02}},
  299. {0x6F,1,{0x02}},
  300. {0x70,1,{0x02}},
  301. {0x71,1,{0x02}},
  302. {0x72,1,{0x06}},
  303. {0x73,1,{0x02}},
  304. {0x74,1,{0x02}},
  305. {0x75,1,{0x14}},
  306. {0x76,1,{0x15}},
  307. {0x77,1,{0x11}},
  308. {0x78,1,{0x10}},
  309. {0x79,1,{0x0F}},
  310. {0x7A,1,{0x0E}},
  311. {0x7B,1,{0x0D}},
  312. {0x7C,1,{0x0C}},
  313. {0x7D,1,{0x06}},
  314. {0x7E,1,{0x02}},
  315. {0x7F,1,{0x0A}},
  316. {0x80,1,{0x02}},
  317. {0x81,1,{0x02}},
  318. {0x82,1,{0x02}},
  319. {0x83,1,{0x02}},
  320. {0x84,1,{0x02}},
  321. {0x85,1,{0x02}},
  322. {0x86,1,{0x02}},
  323. {0x87,1,{0x02}},
  324. {0x88,1,{0x08}},
  325. {0x89,1,{0x02}},
  326. {0x8A,1,{0x02}},
  327. {0xFF,3,{0x98,0x81,0x04}},
  328. {0x6C,1,{0x15}},
  329. {0x6E,1,{0x3B}},
  330. {0xb5,1,{0x06}},
  331. {0x31,1,{0x75}},
  332. {0x6F,1,{0x57}}, // reg vcl + pumping ratio VGH=4x VGL=-2.5x
  333. {0x3A,1,{0xA4}},
  334. {0x8D,1,{0x15}},
  335. {0x87,1,{0xBA}},
  336. {0x26,1,{0x76}},
  337. {0XB2,1,{0XD1}},
  338. {0X88,1,{0X0B}},
  339. {0xFF,3,{0x98,0x81,0x01}},
  340. {0x22,1,{0x0A}},
  341. {0x31,1,{0x00}},
  342. {0x53,1,{0x8A}},
  343. {0x55,1,{0x88}},
  344. {0x50,1,{0xA0}},
  345. {0x51,1,{0xA0}},
  346. {0x60,1,{0x14}},
  347. {0xA0,1,{0x08}},
  348. {0xA1,1,{0x21}},
  349. {0xA2,1,{0x30}},
  350. {0xA3,1,{0x0F}},
  351. {0xA4,1,{0x11}},
  352. {0xA5,1,{0x27}},
  353. {0xA6,1,{0x1C}},
  354. {0xA7,1,{0x1E}},
  355. {0xA8,1,{0x8C}},
  356. {0xA9,1,{0x1B}},
  357. {0xAA,1,{0x28}},
  358. {0xAB,1,{0x74}},
  359. {0xAC,1,{0x1A}},
  360. {0xAD,1,{0x19}},
  361. {0xAE,1,{0x4D}},
  362. {0xAF,1,{0x21}},
  363. {0xB0,1,{0x28}},
  364. {0xB1,1,{0x4a}},
  365. {0xB2,1,{0x5b}},
  366. {0xB3,1,{0x2C}},
  367. {0xC0,1,{0x08}},
  368. {0xC1,1,{0x21}},
  369. {0xC2,1,{0x30}},
  370. {0xC3,1,{0x0F}},
  371. {0xC4,1,{0x11}},
  372. {0xC5,1,{0x27}},
  373. {0xC6,1,{0x1C}},
  374. {0xC7,1,{0x1E}},
  375. {0xC8,1,{0x8C}},
  376. {0xC9,1,{0x1B}},
  377. {0xCA,1,{0x28}},
  378. {0xCB,1,{0x74}},
  379. {0xCC,1,{0x1A}},
  380. {0xCD,1,{0x19}},
  381. {0xCE,1,{0x4D}},
  382. {0xCF,1,{0x21}},
  383. {0xD0,1,{0x28}},
  384. {0xD1,1,{0x4a}},
  385. {0xD2,1,{0x59}},
  386. {0xD3,1,{0x2C}},
  387. {0xFF,3,{0x98,0x81,0x00}},
  388. {0x35,1,{0x00}},
  389. {0x11,1,{0x00}},
  390. {REGFLAG_DELAY, 120, {}},
  391. {0x29,1,{0x00}},
  392. {REGFLAG_DELAY, 20, {}},
  393. {REGFLAG_END_OF_TABLE, 0x00, {}},
  394. };
  395.  
  396.  
  397. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  398. {0x28,1,{0x00}}, // Display off
  399. {REGFLAG_DELAY, 20, {}},
  400. {0x10,1,{0x00}}, // Enter Sleep mode
  401. {REGFLAG_DELAY, 120, {}},
  402. {REGFLAG_END_OF_TABLE, 0x00, {}},
  403. };
  404.  
  405.  
  406. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  407. {
  408. unsigned int i;
  409.  
  410. for (i = 0; i < count; i++) {
  411.  
  412. unsigned cmd;
  413.  
  414. cmd = table[i].cmd;
  415.  
  416. switch (cmd) {
  417.  
  418. case REGFLAG_DELAY:
  419. MDELAY(table[i].count);
  420. break;
  421.  
  422. case REGFLAG_END_OF_TABLE:
  423. break;
  424.  
  425. default:
  426. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  427. }
  428. }
  429.  
  430. }
  431.  
  432.  
  433. /* --------------------------------------------------------------------------- */
  434. /* LCM Driver Implementations */
  435. /* --------------------------------------------------------------------------- */
  436.  
  437. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  438. {
  439. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  440. }
  441.  
  442.  
  443. static void lcm_get_params(LCM_PARAMS *params)
  444. {
  445.  
  446. memset(params, 0, sizeof(LCM_PARAMS));
  447.  
  448. params->type = LCM_TYPE_DSI;
  449.  
  450. params->width = FRAME_WIDTH;
  451. params->height = FRAME_HEIGHT;
  452.  
  453. params->dsi.mode = SYNC_PULSE_VDO_MODE;
  454.  
  455. // DSI
  456. /* Command mode setting */
  457. //1 Three lane or Four lane
  458. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  459. //The following defined the fomat for data coming from LCD engine.
  460. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  461.  
  462. // Video mode setting
  463. params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
  464.  
  465. params->dsi.vertical_sync_active = 8;// 3 2
  466. params->dsi.vertical_backporch = 18;// 20 1
  467. params->dsi.vertical_frontporch = 20; // 1 12
  468. params->dsi.vertical_active_line = FRAME_HEIGHT;
  469.  
  470. params->dsi.horizontal_sync_active = 20;// 50 2
  471. params->dsi.horizontal_backporch = 60;//90
  472. params->dsi.horizontal_frontporch = 70;//90
  473. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  474. // params->dsi.ssc_disable = 1;
  475. params->dsi.HS_TRAIL = 6;
  476. /*ui = 1000/(dis_params->PLL_CLOCK*2) + 0x01;
  477. cycle_time = 8000/(dis_params->PLL_CLOCK*2) + 0x01;
  478. HS_TRAIL = (0x04*ui + 0x50)/cycle_time;*/
  479. //params->dsi.LPX=8;
  480.  
  481. // Bit rate calculation
  482. //1 Every lane speed
  483. //params->dsi.pll_select=1;
  484. //params->dsi.PLL_CLOCK = LCM_DSI_6589_PLL_CLOCK_377;
  485. params->dsi.PLL_CLOCK=215;//208//270
  486. //params->dsi.noncont_clock=1;
  487. //params->dsi.noncont_clock_period=2;
  488. //params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps
  489. //params->dsi.pll_div2=0; // div2=0,1,2,3;div1_real=1,2,4,4
  490.  
  491. // params->dsi.fbk_div =7; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)
  492. //params->dsi.compatibility_for_nvk = 1; // this parameter would be set to 1 if DriverIC is NTK's and when force match DSI clock for NTK's
  493. params->dsi.esd_check_enable = 1;
  494. params->dsi.customization_esd_check_enable = 1;
  495. params->dsi.lcm_esd_check_table[0].cmd = 0x09;
  496. params->dsi.lcm_esd_check_table[0].count = 3;
  497. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x80;
  498. params->dsi.lcm_esd_check_table[0].para_list[1] = 0x03;
  499. params->dsi.lcm_esd_check_table[0].para_list[2] = 0x06;
  500. }
  501.  
  502. #ifdef BUILD_LK
  503. #include <platform/mt_gpio.h>
  504. #include <platform/mt_i2c.h>
  505. #include <platform/mt_pmic.h>
  506.  
  507. #define TPS65132_SLAVE_ADDR_WRITE 0x7C
  508. static struct mt_i2c_t TPS65132_i2c;
  509.  
  510. static int TPS65132_write_byte(kal_uint8 addr, kal_uint8 value)
  511. {
  512. kal_uint32 ret_code = I2C_OK;
  513. kal_uint8 write_data[2];
  514. kal_uint16 len;
  515.  
  516. write_data[0]= addr;
  517. write_data[1] = value;
  518.  
  519. TPS65132_i2c.id = 1;//I2C2;
  520. /* Since i2c will left shift 1 bit, we need to set FAN5405 I2C address to >>1 */
  521. TPS65132_i2c.addr = (TPS65132_SLAVE_ADDR_WRITE >> 1);
  522. TPS65132_i2c.mode = ST_MODE;
  523. TPS65132_i2c.speed = 100;
  524. len = 2;
  525.  
  526. ret_code = i2c_write(&TPS65132_i2c, write_data, len);
  527. //printf("%s: i2c_write: ret_code: %d\n", __func__, ret_code);
  528.  
  529. return ret_code;
  530. }
  531. #endif
  532.  
  533. static unsigned int lcm_compare_id(void)
  534. {
  535. int array[4], ret=0;
  536. char buffer[3];
  537. int id=0;
  538.  
  539. mt_set_gpio_mode(GPIO_LCD_ENP, GPIO_MODE_00);
  540. mt_set_gpio_dir(GPIO_LCD_ENP, GPIO_DIR_OUT);
  541. mt_set_gpio_out(GPIO_LCD_ENP, GPIO_OUT_ONE);
  542.  
  543. #ifdef BUILD_LK
  544. ret=TPS65132_write_byte(0x0 ,0xC); //5.2V
  545. if(ret)
  546. printf("[LK]ili9881c_dsi_vdo_txd ----tps65132----ret=%0x--i2c write error----\n",ret);
  547. else
  548. printf("[LK]ili9881c_dsi_vdo_txd ----tps6132----ret=%0x--i2c write success----\n",ret);
  549. #else
  550. ret=tps65132_write_bytes(0x0, 0xC);
  551.  
  552. if(ret<0)
  553. pr_debug("[KERNEL]ili9881c_dsi_vdo_txd ----tps65132---ret=%0x-- i2c write error-----\n",ret);
  554. else
  555. pr_debug("[KERNEL]ili9881c_dsi_vdo_txd ----tps65132---ret=%0x-- i2c write success-----\n",ret);
  556. #endif
  557. MDELAY(5);
  558. mt_set_gpio_mode(GPIO_LCD_ENN, GPIO_MODE_00);
  559. mt_set_gpio_dir(GPIO_LCD_ENN, GPIO_DIR_OUT);
  560. mt_set_gpio_out(GPIO_LCD_ENN, GPIO_OUT_ONE);
  561. #ifdef BUILD_LK
  562. ret=TPS65132_write_byte(0x1, 0xC); //-5.2v
  563. if(ret)
  564. dprintf(0, "[LK]ili9881c_dsi_vdo_txd ----tps65132----ret=%0x--i2c write error----\n",ret);
  565. else
  566. dprintf(0, "[LK]ili9881c_dsi_vdo_txd ----tps65132----ret=%0x--i2c write success----\n",ret);
  567. #else
  568. ret=tps65132_write_bytes(0x1, 0xC);
  569. if(ret<0)
  570. pr_debug("[KERNEL]ili9881c_dsi_vdo_txd ----tps6132---ret=%0x-- i2c write error-----\n",ret);
  571. else
  572. pr_debug("[KERNEL]ili9881c_dsi_vdo_txd ----tps6132---ret=%0x-- i2c write success-----\n",ret);
  573. #endif
  574. MDELAY(5);
  575.  
  576. SET_RESET_PIN(1);
  577. MDELAY(20);
  578. SET_RESET_PIN(0);
  579. MDELAY(20);
  580. SET_RESET_PIN(1);
  581. MDELAY(100);
  582.  
  583. //{0x39, 0xFF, 5, { 0xFF,0x98,0x06,0x04,0x01}}, // Change to Page 1 CMD
  584. array[0] = 0x00043902;
  585. array[1] = 0x018198FF;
  586. dsi_set_cmdq(array, 2, 1);
  587.  
  588. array[0] = 0x00013700;
  589. dsi_set_cmdq(array, 1, 1);
  590. read_reg_v2(0x00, &buffer[0], 1); //0x98
  591.  
  592. id = buffer[0];
  593.  
  594.  
  595. #ifdef BUILD_LK
  596. printf("jinmin ili9881c_dsi_vdo_txd [lk]=%d %d %d \n", buffer[0],buffer[1], buffer[2]);
  597. printf("id =0x%x\n", id);
  598. #else
  599. pr_debug("jinmin ili9881c_dsi_vdo_txd [kernel]=%d %d %d \n", buffer[0],buffer[1], buffer[2]);
  600. pr_debug("id =0x%x\n", id);
  601. #endif
  602.  
  603. if (0x98==id ) {
  604. return 1;
  605. }
  606. else
  607. return 0;
  608. }
  609.  
  610. static void lcm_init(void)
  611. {
  612. int ret=0;
  613.  
  614. mt_set_gpio_mode(GPIO_LCD_ENP, GPIO_MODE_00);
  615. mt_set_gpio_dir(GPIO_LCD_ENP, GPIO_DIR_OUT);
  616. mt_set_gpio_out(GPIO_LCD_ENP, GPIO_OUT_ONE);
  617. #ifdef BUILD_LK
  618. ret=TPS65132_write_byte(0x0, 0xC); //5.2V
  619. if(ret)
  620. dprintf("[LK]ili9881c_txd ----tps6132----ret=%0x--i2c write error----\n",ret);
  621. else
  622. dprintf("[LK]ili9881c_txd ----tps6132----ret=%0x--i2c write success----\n",ret);
  623. #else
  624. ret=tps65132_write_bytes(0x0, 0xC);
  625.  
  626. if(ret<0)
  627. pr_debug("[KERNEL]ili9881c_txd ----tps6132---ret=%0x-- i2c write error-----\n",ret);
  628. else
  629. pr_debug("[KERNEL]ili9881c_txd ----tps6132---ret=%0x-- i2c write success-----\n",ret);
  630. #endif
  631. MDELAY(5);
  632.  
  633. mt_set_gpio_mode(GPIO_LCD_ENN, GPIO_MODE_00);
  634. mt_set_gpio_dir(GPIO_LCD_ENN, GPIO_DIR_OUT);
  635. mt_set_gpio_out(GPIO_LCD_ENN, GPIO_OUT_ONE);
  636. #ifdef BUILD_LK
  637. ret=TPS65132_write_byte(0x1, 0xC); //-5.2v
  638. if(ret)
  639. dprintf(0, "[LK]ili9881c_txd ----tps6132----ret=%0x--i2c write error----\n",ret);
  640. else
  641. dprintf(0, "[LK]ili9881c_txd ----tps6132----ret=%0x--i2c write success----\n",ret);
  642. #else
  643. ret=tps65132_write_bytes(0x1, 0xC);
  644. if(ret<0)
  645. pr_debug("[KERNEL]ili9881c_txd ----tps6132---ret=%0x-- i2c write error-----\n",ret);
  646. else
  647. pr_debug("[KERNEL]ili9881c_txd ----tps6132---ret=%0x-- i2c write success-----\n",ret);
  648. #endif
  649. //MDELAY(10);
  650.  
  651. SET_RESET_PIN(1);
  652. MDELAY(1);
  653. SET_RESET_PIN(0);
  654. MDELAY(10);
  655. SET_RESET_PIN(1);
  656. MDELAY(120);
  657. push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  658.  
  659. }
  660.  
  661.  
  662.  
  663. static void lcm_suspend(void)
  664. {
  665. push_table(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  666.  
  667. SET_RESET_PIN(1);
  668. MDELAY(1);
  669. SET_RESET_PIN(0);
  670. MDELAY(10);
  671. SET_RESET_PIN(1);
  672. MDELAY(120);
  673. lcm_set_gpio_out(GPIO_LCD_ENN, 0);//power on +5
  674. MDELAY(10);
  675. lcm_set_gpio_out(GPIO_LCD_ENP, 0);//power on -5
  676. MDELAY(10);
  677. }
  678.  
  679.  
  680. static void lcm_resume(void)
  681. {
  682. #ifdef BUILD_LK
  683. printf("uboot %s\n", __func__);
  684. #else
  685. pr_debug("kernel %s\n", __func__);
  686. #endif
  687. /* push_table(lcm_sleep_out_setting, sizeof(lcm_sleep_out_setting) / sizeof(struct LCM_setting_table), 1); */
  688. lcm_init();
  689. }
  690.  
  691.  
  692. static unsigned int lcm_ata_check(unsigned char *buffer)
  693. {
  694. #ifndef BUILD_LK
  695. int array[4];
  696. char buf[3];
  697. int id=0;
  698.  
  699. array[0] = 0x00043902;
  700. array[1] = 0x018198FF;
  701. dsi_set_cmdq(array, 2, 1);
  702.  
  703. array[0] = 0x00013700;
  704. dsi_set_cmdq(array, 1, 1);
  705. atomic_set(&ESDCheck_byCPU,1);
  706. read_reg_v2(0x00, &buf[0], 1); //0x98
  707. atomic_set(&ESDCheck_byCPU,0);
  708. id = buf[0];
  709. return (0x98 == id)?1:0;
  710. #else
  711. return 0;
  712. #endif
  713. }
  714.  
  715.  
  716. LCM_DRIVER ili9881c_dsi_vdo_txd_lcm_drv = {
  717. .name = "ili9881c_dsi_vdo_txd",
  718. .set_util_funcs = lcm_set_util_funcs,
  719. .get_params = lcm_get_params,
  720. .init = lcm_init,
  721. .suspend = lcm_suspend,
  722. .resume = lcm_resume,
  723. .compare_id = lcm_compare_id,
  724. .ata_check = lcm_ata_check, // я не знаю, что это такое, если не компилируется, то закомментируйте эту строку
  725. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement