lm3632_lk_driver.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //#include <platform/mt_pwm.h>
  2. #include <mt_gpio.h>
  3. #include <mt_i2c.h>
  4. #include <cust_gpio_usage.h>
  5. //#include <lge_bootmode.h>
  6. //#include <platform/boot_mode.h>
  7. #define CPD_TAG "[LK][chargepump] "
  8. #define CPD_FUN(f) printf(CPD_TAG"%s\n", __FUNCTION__)
  9. #define CPD_ERR(fmt, args...) printf(CPD_TAG"%s %d : "fmt, __FUNCTION__, __LINE__, ##args)
  10. #define CPD_LOG(fmt, args...) printf(CPD_TAG fmt, ##args)
  11. #define LM3632_SLAVE_ADDR (0x11<<1)
  12. #define LM3632_CHIP_ENABLE_PIN GPIO_LCD_BL_EN
  13. #define LM3632_CHIP_ENABLE_PIN_MODE GPIO_LCD_BL_EN_M_GPIO
  14. #define LM3632_DSV_VPOS_EN GPIO_DSV_AVEE_EN
  15. #define LM3632_DSV_VPOS_EN_MODE GPIO_DSV_AVEE_EN_M_GPIO
  16. #define LM3632_DSV_VNEG_EN GPIO_DSV_AVDD_EN
  17. #define LM3632_DSV_VNEG_EN_MODE GPIO_DSV_AVDD_EN_M_GPIO
  18. static unsigned long lm3632_i2c_write_byte(unsigned char reg_addr, unsigned char data)
  19. {
  20. unsigned long ret_code = I2C_OK;
  21. unsigned char write_data[I2C_FIFO_SIZE];
  22. unsigned char slave_addr = LM3632_SLAVE_ADDR;
  23. write_data[0] = reg_addr;
  24. write_data[1] = data;
  25. ret_code = mt_i2c_write(I2C2, slave_addr, write_data, 2, 0);
  26. return ret_code;
  27. }
  28. static int lm3632_hw_init()
  29. {
  30. int ret_code;
  31. CPD_FUN();
  32. // GPIO for DSV setting
  33. mt_set_gpio_mode(LM3632_DSV_VPOS_EN, LM3632_DSV_VPOS_EN_MODE);
  34. mt_set_gpio_pull_enable(LM3632_DSV_VPOS_EN, GPIO_PULL_ENABLE);
  35. mt_set_gpio_dir(LM3632_DSV_VPOS_EN, GPIO_DIR_OUT);
  36. mt_set_gpio_mode(LM3632_DSV_VNEG_EN, LM3632_DSV_VNEG_EN_MODE);
  37. mt_set_gpio_pull_enable(LM3632_DSV_VNEG_EN, GPIO_PULL_ENABLE);
  38. mt_set_gpio_dir(LM3632_DSV_VNEG_EN, GPIO_DIR_OUT);
  39. // Backlight Enable Pin
  40. mt_set_gpio_mode(LM3632_CHIP_ENABLE_PIN, LM3632_CHIP_ENABLE_PIN_MODE);
  41. mt_set_gpio_dir(LM3632_CHIP_ENABLE_PIN, GPIO_DIR_OUT);
  42. mt_set_gpio_out(LM3632_CHIP_ENABLE_PIN, GPIO_OUT_ONE);
  43. udelay(100);
  44. mt_set_gpio_out(LM3632_CHIP_ENABLE_PIN,GPIO_OUT_ZERO);
  45. udelay(10000);
  46. mt_set_gpio_out(LM3632_CHIP_ENABLE_PIN,GPIO_OUT_ONE);
  47. udelay(10);
  48. ret_code = lm3632_i2c_write_byte(0x02, 0x70); // OVP 29V, linear mode, TI recommand
  49. if(ret_code != I2C_OK) {
  50. CPD_ERR("I2C fail: %d\n", ret_code);
  51. return ret_code;
  52. }
  53. // LCM bias(Vpos, Vneg) controlled by external pin, not I2C
  54. ret_code = lm3632_i2c_write_byte(0x0C, 0x01); // VPOS_EN=0, VNEG_EN=0, EXT_EN=1
  55. if(ret_code != I2C_OK) {
  56. CPD_ERR("I2C fail: %d\n", ret_code);
  57. return ret_code;
  58. }
  59. // Vpos voltage setting as +5.5v
  60. ret_code = lm3632_i2c_write_byte(0x0E, 0x1E);
  61. if(ret_code != I2C_OK) {
  62. CPD_ERR("I2C fail: %d\n", ret_code);
  63. return ret_code;
  64. }
  65. // Vneg voltage setting as -5.5v
  66. ret_code = lm3632_i2c_write_byte(0x0F, 0x1E);
  67. if(ret_code != I2C_OK) {
  68. CPD_ERR("I2C fail: %d\n", ret_code);
  69. return ret_code;
  70. }
  71. return 0;
  72. }
  73. static int get_backlight_enable=0;
  74. int chargepump_set_backlight_level(int level)
  75. {
  76. unsigned char cmd = 0x0;
  77. int cmd_len = 1;
  78. unsigned char data = 0x00;
  79. int data_len = 1;
  80. unsigned long ret_code;
  81. int i = 0;
  82. if(get_backlight_enable == 0)
  83. {
  84. lm3632_hw_init();
  85. get_backlight_enable=1;
  86. }
  87. CPD_LOG("chargepump_set_backlight_level, level : %d\n", level);
  88. if(level != 0)
  89. {
  90. // Backlight brightness setting
  91. ret_code = lm3632_i2c_write_byte(0x04, 0x07); // Backlight brightness LSB 3bits, 0b111
  92. if(ret_code != I2C_OK) {
  93. CPD_ERR("I2C fail: %d\n", ret_code);
  94. return ret_code;
  95. }
  96. if(level == 33) //download mode
  97. {
  98. ret_code = lm3632_i2c_write_byte(0x05, 0xb2); // Backlight brightness MSB 8bits, 7/10 of Max brightness
  99. }
  100. else
  101. {
  102. ret_code = lm3632_i2c_write_byte(0x05, 0xff); // Max Brightness
  103. }
  104. if(ret_code != I2C_OK) {
  105. CPD_ERR("I2C fail: %d\n", ret_code);
  106. return ret_code;
  107. }
  108. // backlight enable
  109. ret_code = lm3632_i2c_write_byte(0x0A, 0x11); // TI recommand, BL_EN enable
  110. if(ret_code != I2C_OK) {
  111. CPD_ERR("I2C fail: %d\n", ret_code);
  112. return ret_code;
  113. }
  114. }
  115. else
  116. {
  117. // backlight disable
  118. ret_code = lm3632_i2c_write_byte(0x0A, 0x10); // BL_EN == 0
  119. if(ret_code != I2C_OK) {
  120. CPD_ERR("I2C fail: %d\n", ret_code);
  121. return ret_code;
  122. }
  123. }
  124. return 1;
  125. }
  126. void chargepump_DSV_on()
  127. {
  128. //CPD_FUN();
  129. mt_set_gpio_out(LM3632_DSV_VPOS_EN, GPIO_OUT_ONE);
  130. mdelay(1);
  131. mt_set_gpio_out(LM3632_DSV_VNEG_EN, GPIO_OUT_ONE);
  132. }
  133. void chargepump_DSV_off()
  134. {
  135. //CPD_FUN();
  136. mt_set_gpio_out(LM3632_DSV_VPOS_EN, GPIO_OUT_ZERO);
  137. mdelay(1);
  138. mt_set_gpio_out(LM3632_DSV_VNEG_EN, GPIO_OUT_ZERO);
  139. }