qbg.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __QBG_H__
  7. #define __QBG_H__
  8. #include <linux/types.h>
  9. #define MAX_FIFO_COUNT 36
  10. #define QBG_MAX_STEP_CHG_ENTRIES 6
  11. #define QBG_QBGIOCXCFG 0x01
  12. #define QBG_QBGIOCXEPR 0x02
  13. #define QBG_QBGIOCXEPW 0x03
  14. #define QBG_QBGIOCXSTEPCHGCFG 0x04
  15. enum QBG_STATE {
  16. QBG_LPM,
  17. QBG_MPM,
  18. QBG_HPM,
  19. QBG_FAST_CHAR,
  20. QBG_PON_OCV,
  21. QBG_STATE_MAX,
  22. };
  23. enum QBG_SDAM_DATA_OFFSET {
  24. QBG_ACC0_OFFSET = 0,
  25. QBG_ACC1_OFFSET = 2,
  26. QBG_ACC2_OFFSET = 4,
  27. QBG_TBAT_OFFSET = 6,
  28. QBG_IBAT_OFFSET = 8,
  29. QBG_VREF_OFFSET = 10,
  30. QBG_DATA_TAG_OFFSET = 12,
  31. QBG_QG_STS_OFFSET,
  32. QBG_STS1_OFFSET,
  33. QBG_STS2_OFFSET,
  34. QBG_STS3_OFFSET,
  35. QBG_ONE_FIFO_LENGTH,
  36. };
  37. enum qbg {
  38. QBG_PARAM_SOC,
  39. QBG_PARAM_BATT_SOC,
  40. QBG_PARAM_SYS_SOC,
  41. QBG_PARAM_ESR,
  42. QBG_PARAM_OCV_UV,
  43. QBG_PARAM_MAX_LOAD_NOW,
  44. QBG_PARAM_MAX_LOAD_AVG,
  45. QBG_PARAM_HOLD_SOC_100PCT,
  46. QBG_PARAM_CHARGE_CYCLE_COUNT,
  47. QBG_PARAM_LEARNED_CAPACITY,
  48. QBG_PARAM_TTF_100MS,
  49. QBG_PARAM_TTE_100MS,
  50. QBG_PARAM_SOH,
  51. QBG_PARAM_TBAT,
  52. QBG_PARAM_SYS_SOC_HOLD_100PCT,
  53. QBG_PARAM_JEITA_COOL_THRESHOLD,
  54. QBG_PARAM_TOTAL_IMPEDANCE,
  55. QBG_PARAM_ESSENTIAL_PARAM_REVID,
  56. QBG_PARAM_FIFO_TIMESTAMP,
  57. QBG_PARAM_MAX,
  58. };
  59. struct qbg_essential_params {
  60. short int msoc;
  61. short int cutoff_soc;
  62. short int full_soc;
  63. short int x0;
  64. short int x1;
  65. short int x2;
  66. short int soh_r;
  67. short int soh_c;
  68. short int theta0;
  69. short int theta1;
  70. short int theta2;
  71. short int i1full;
  72. short int i2full;
  73. short int i1cutoff;
  74. short int i2cutoff;
  75. short int syssoc;
  76. int discharge_cycle_count;
  77. int charge_cycle_count;
  78. unsigned int rtc_time;
  79. short int batt_therm;
  80. unsigned short int ocv;
  81. } __attribute__ ((__packed__));
  82. struct fifo_data {
  83. unsigned short int v1;
  84. unsigned short int v2;
  85. unsigned short int i;
  86. unsigned short int tbat;
  87. unsigned short int ibat;
  88. unsigned short int vref;
  89. char data_tag;
  90. char qg_sts;
  91. char sts1;
  92. char sts2;
  93. char sts3;
  94. } __attribute__ ((__packed__));
  95. struct k_fifo_data {
  96. unsigned int v1;
  97. unsigned int v2;
  98. unsigned int i;
  99. unsigned int tbat;
  100. unsigned int ibat;
  101. unsigned int vref;
  102. unsigned int data_tag;
  103. unsigned int qg_sts;
  104. unsigned int sts1;
  105. unsigned int sts2;
  106. unsigned int sts3;
  107. } __attribute__ ((__packed__));
  108. struct qbg_config {
  109. unsigned int batt_id;
  110. unsigned int pon_ocv;
  111. unsigned int pon_ibat;
  112. unsigned int pon_tbat;
  113. unsigned int pon_soc;
  114. unsigned int float_volt_uv;
  115. unsigned int fastchg_curr_ma;
  116. unsigned int vbat_cutoff_mv;
  117. unsigned int ibat_cutoff_ma;
  118. unsigned int vph_min_mv;
  119. unsigned int iterm_ma;
  120. unsigned int rconn_mohm;
  121. __u64 current_time;
  122. unsigned int sdam_batt_id;
  123. unsigned int essential_param_revid;
  124. __u64 sample_time_us[QBG_STATE_MAX];
  125. } __attribute__ ((__packed__));
  126. struct qbg_param {
  127. unsigned int data;
  128. _Bool valid;
  129. };
  130. struct qbg_kernel_data {
  131. unsigned int seq_no;
  132. unsigned int fifo_time;
  133. unsigned int fifo_count;
  134. struct k_fifo_data fifo[MAX_FIFO_COUNT];
  135. struct qbg_param param[QBG_PARAM_MAX];
  136. } __attribute__ ((__packed__));
  137. struct qbg_user_data {
  138. struct qbg_param param[QBG_PARAM_MAX];
  139. } __attribute__ ((__packed__));
  140. struct range_data {
  141. int low_threshold;
  142. int high_threshold;
  143. unsigned int value;
  144. } __attribute__ ((__packed__));
  145. struct ranges {
  146. struct range_data data[QBG_MAX_STEP_CHG_ENTRIES];
  147. unsigned char range_count;
  148. _Bool valid;
  149. } __attribute__((__packed__));
  150. struct qbg_step_chg_jeita_params {
  151. int jeita_full_fv_10nv;
  152. int jeita_full_iterm_10na;
  153. int jeita_warm_adc_value;
  154. int jeita_cool_adc_value;
  155. int battery_beta;
  156. int battery_therm_kohm;
  157. struct ranges step_fcc_cfg;
  158. struct ranges jeita_fcc_cfg;
  159. struct ranges jeita_fv_cfg;
  160. unsigned char ttf_calc_mode;
  161. } __attribute__ ((__packed__));
  162. /* IOCTLs to read & write QBG config and essential params */
  163. #define QBGIOCXCFG _IOR('B', 0x01, struct qbg_config)
  164. #define QBGIOCXEPR _IOR('B', 0x02, struct qbg_essential_params)
  165. #define QBGIOCXEPW _IOWR('B', 0x03, struct qbg_essential_params)
  166. #define QBGIOCXSTEPCHGCFG _IOWR('B', 0x04, struct qbg_step_chg_jeita_params)
  167. #endif