lcm_i2c.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #if defined(MTK_LCM_DEVICE_TREE_SUPPORT)
  36. #include <debug.h>
  37. #include <stdio.h>
  38. #include <stdint.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include <platform.h>
  42. #include <platform/mt_typedefs.h>
  43. #include <platform/upmu_common.h>
  44. #include <platform/upmu_hw.h>
  45. #include <platform/mt_gpio.h>
  46. #include <platform/mt_i2c.h>
  47. #include <platform/mt_pmic.h>
  48. #include <cust_i2c.h>
  49. #include "lcm_define.h"
  50. #include "lcm_drv.h"
  51. #include "lcm_i2c.h"
  52. static struct mt_i2c_t tps65132_i2c;
  53. #define LCM_I2C_ID I2C_I2C_LCD_BIAS_CHANNEL
  54. /* Since i2c will left shift 1 bit, we need to set FAN5405 I2C address to >>1 */
  55. #define LCM_I2C_ADDR (I2C_I2C_LCD_BIAS_SLAVE_7_BIT_ADDR >> 1)
  56. #define LCM_I2C_MODE ST_MODE
  57. #define LCM_I2C_SPEED 100
  58. static LCM_STATUS _lcm_i2c_check_data(char type, const LCM_DATA_T2 *t2)
  59. {
  60. switch (type) {
  61. case LCM_I2C_WRITE:
  62. if (t2->cmd > 0xFF) {
  63. dprintf(0, "[LCM][ERROR] %s: %d \n", __func__, (unsigned int)t2->cmd);
  64. return LCM_STATUS_ERROR;
  65. }
  66. if (t2->data > 0xFF) {
  67. dprintf(0, "[LCM][ERROR] %s: %d \n", __func__, (unsigned int)t2->data);
  68. return LCM_STATUS_ERROR;
  69. }
  70. break;
  71. default:
  72. dprintf(0, "[LCM][ERROR] %s: %d\n", __func__, (unsigned int)type);
  73. return LCM_STATUS_ERROR;
  74. }
  75. return LCM_STATUS_OK;
  76. }
  77. static int _lcm_i2c_write_bytes(kal_uint8 addr, kal_uint8 value)
  78. {
  79. kal_int32 ret_code = I2C_OK;
  80. kal_uint8 write_data[2];
  81. kal_uint16 len;
  82. write_data[0]= addr;
  83. write_data[1] = value;
  84. tps65132_i2c.id = LCM_I2C_ID;
  85. /* Since i2c will left shift 1 bit, we need to set FAN5405 I2C address to >>1 */
  86. tps65132_i2c.addr = LCM_I2C_ADDR;
  87. tps65132_i2c.mode = LCM_I2C_MODE;
  88. tps65132_i2c.speed = LCM_I2C_SPEED;
  89. len = 2;
  90. ret_code = i2c_write(&tps65132_i2c, write_data, len);
  91. if (ret_code<0)
  92. dprintf(0, "[LCM][ERROR] %s: %d\n", __func__, ret_code);
  93. return ret_code;
  94. }
  95. LCM_STATUS lcm_i2c_set_data(char type, const LCM_DATA_T2 *t2)
  96. {
  97. kal_uint32 ret_code = I2C_OK;
  98. // check parameter is valid
  99. if (LCM_STATUS_OK == _lcm_i2c_check_data(type, t2)) {
  100. switch (type) {
  101. case LCM_I2C_WRITE:
  102. ret_code = _lcm_i2c_write_bytes((kal_uint8)t2->cmd, (kal_uint8)t2->data);
  103. break;
  104. default:
  105. dprintf(0, "[LCM][ERROR] %s: %d\n", __func__, (unsigned int)type);
  106. return LCM_STATUS_ERROR;
  107. }
  108. } else {
  109. dprintf(0, "[LCM][ERROR] %s: %d, 0x%x, 0x%x\n", __func__, (unsigned int)type, (unsigned int)t2->cmd, (unsigned int)t2->data);
  110. return LCM_STATUS_ERROR;
  111. }
  112. if (ret_code != I2C_OK) {
  113. dprintf(0, "[LCM][ERROR] %s: 0x%x, 0x%x, %d\n", __func__, (unsigned int)t2->cmd, (unsigned int)t2->data, ret_code);
  114. return LCM_STATUS_ERROR;
  115. }
  116. return LCM_STATUS_OK;
  117. }
  118. #endif