sec_adc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * sec_adc.c
  3. * Samsung Mobile Battery Driver
  4. *
  5. * Copyright (C) 2012 Samsung Electronics
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/battery/sec_adc.h>
  13. static int current_chip_vendor;
  14. static void sec_bat_adc_ap_init(struct platform_device *pdev)
  15. {
  16. /*
  17. struct power_supply *psy_fuelgauge = get_power_supply_by_name("sec-fuelgauge");
  18. struct sec_fuelgauge_info *fuelgauge =
  19. container_of(psy_fuelgauge, struct sec_fuelgauge_info, psy_fg);
  20. */
  21. pr_info("%s: chip vendor %d\n", __func__, current_chip_vendor);
  22. switch (current_chip_vendor)
  23. {
  24. case VENDOR_LSI :
  25. break;
  26. case VENDOR_QCOM :
  27. break;
  28. default :
  29. break;
  30. }
  31. }
  32. static int sec_bat_adc_ap_read(void)
  33. {
  34. int data = -1;
  35. int rc = -1;
  36. struct qpnp_vadc_result results;
  37. switch (current_chip_vendor)
  38. {
  39. case VENDOR_LSI :
  40. break;
  41. case VENDOR_QCOM :
  42. #if defined(CONFIG_ARCH_MSM8974PRO)
  43. rc = qpnp_vadc_read(adc_client, LR_MUX5_PU1_AMUX_THM2, &results);
  44. #else
  45. rc = qpnp_vadc_read(NULL, LR_MUX5_PU2_AMUX_THM2, &results);
  46. #endif
  47. if (rc) {
  48. pr_err("%s: Unable to read batt temperature rc=%d\n",
  49. __func__, rc);
  50. return 0;
  51. }
  52. pr_err("%s: adc %d\n",
  53. __func__, results.adc_code);
  54. data = results.adc_code;
  55. break;
  56. default :
  57. break;
  58. }
  59. pr_info("%s: [%d] data = %d\n", __func__, current_chip_vendor, data);
  60. return data;
  61. }
  62. static void sec_bat_adc_ap_exit(void)
  63. {
  64. }
  65. static void sec_bat_adc_none_init(struct platform_device *pdev)
  66. {
  67. }
  68. static int sec_bat_adc_none_read(void)
  69. {
  70. return 0;
  71. }
  72. static void sec_bat_adc_none_exit(void)
  73. {
  74. }
  75. static void sec_bat_adc_ic_init(struct platform_device *pdev)
  76. {
  77. }
  78. static int sec_bat_adc_ic_read(void)
  79. {
  80. return 0;
  81. }
  82. static void sec_bat_adc_ic_exit(void)
  83. {
  84. }
  85. static int adc_read_type(struct sec_battery_info *battery)
  86. {
  87. int adc = 0;
  88. switch (battery->pdata->temp_adc_type)
  89. {
  90. case SEC_BATTERY_ADC_TYPE_NONE :
  91. adc = sec_bat_adc_none_read();
  92. break;
  93. case SEC_BATTERY_ADC_TYPE_AP :
  94. adc = sec_bat_adc_ap_read();
  95. break;
  96. case SEC_BATTERY_ADC_TYPE_IC :
  97. adc = sec_bat_adc_ic_read();
  98. break;
  99. case SEC_BATTERY_ADC_TYPE_NUM :
  100. break;
  101. default :
  102. break;
  103. }
  104. pr_info("[%s]ADC = %d\n", __func__, adc);
  105. return adc;
  106. }
  107. static void adc_init_type(struct platform_device *pdev,
  108. struct sec_battery_info *battery)
  109. {
  110. switch (battery->pdata->temp_adc_type)
  111. {
  112. case SEC_BATTERY_ADC_TYPE_NONE :
  113. sec_bat_adc_none_init(pdev);
  114. break;
  115. case SEC_BATTERY_ADC_TYPE_AP :
  116. sec_bat_adc_ap_init(pdev);
  117. break;
  118. case SEC_BATTERY_ADC_TYPE_IC :
  119. sec_bat_adc_ic_init(pdev);
  120. break;
  121. case SEC_BATTERY_ADC_TYPE_NUM :
  122. break;
  123. default :
  124. break;
  125. }
  126. }
  127. static void adc_exit_type(struct sec_battery_info *battery)
  128. {
  129. switch (battery->pdata->temp_adc_type)
  130. {
  131. case SEC_BATTERY_ADC_TYPE_NONE :
  132. sec_bat_adc_none_exit();
  133. break;
  134. case SEC_BATTERY_ADC_TYPE_AP :
  135. sec_bat_adc_ap_exit();
  136. break;
  137. case SEC_BATTERY_ADC_TYPE_IC :
  138. sec_bat_adc_ic_exit();
  139. break;
  140. case SEC_BATTERY_ADC_TYPE_NUM :
  141. break;
  142. default :
  143. break;
  144. }
  145. }
  146. int adc_read(struct sec_battery_info *battery)
  147. {
  148. int adc = 0;
  149. adc = adc_read_type(battery);
  150. pr_info("[%s]adc = %d\n", __func__, adc);
  151. return adc;
  152. }
  153. void adc_init(struct platform_device *pdev, struct sec_battery_info *battery)
  154. {
  155. if (!battery->pdata->chip_vendor) {
  156. pr_err("%s: chip vendor is empty\n", __func__);
  157. return ;
  158. }
  159. pr_info("[%s]CHIP VENDOR = %s\n", __func__, battery->pdata->chip_vendor);
  160. if (!strcmp(battery->pdata->chip_vendor, "LSI"))
  161. current_chip_vendor = VENDOR_LSI;
  162. else if (!strcmp(battery->pdata->chip_vendor, "QCOM"))
  163. current_chip_vendor = VENDOR_QCOM;
  164. else
  165. current_chip_vendor = VENDOR_UNKNOWN;
  166. adc_init_type(pdev, battery);
  167. }
  168. void adc_exit(struct sec_battery_info *battery)
  169. {
  170. adc_exit_type(battery);
  171. }