sec_pd.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * include/linux/battery/sec_pd.h
  3. *
  4. * header file supporting samsung pd information
  5. *
  6. * Copyright (C) 2020 Samsung Electronics
  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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #ifndef __SEC_PD_H__
  24. #define __SEC_PD_H__
  25. #define MAX_PDO_NUM 8
  26. #define AVAILABLE_VOLTAGE 9000
  27. #define DEFAULT_VOLTAGE 5000
  28. #define UNIT_FOR_VOLTAGE 50
  29. #define UNIT_FOR_CURRENT 10
  30. #define UNIT_FOR_APDO_VOLTAGE 100
  31. #define UNIT_FOR_APDO_CURRENT 50
  32. /* d2d 15w authentication information */
  33. #define AUTH_VENDOR_ID 0x04e8
  34. #define AUTH_PRODUCT_ID 0x6860
  35. typedef enum {
  36. PDIC_NOTIFY_EVENT_DETACH = 0,
  37. PDIC_NOTIFY_EVENT_PDIC_ATTACH,
  38. PDIC_NOTIFY_EVENT_PD_SINK,
  39. PDIC_NOTIFY_EVENT_PD_SOURCE,
  40. PDIC_NOTIFY_EVENT_PD_SINK_CAP,
  41. PDIC_NOTIFY_EVENT_PD_PRSWAP_SNKTOSRC,
  42. PDIC_NOTIFY_EVENT_PD_PRSWAP_SRCTOSNK,
  43. } pdic_notifier_event_t;
  44. typedef enum
  45. {
  46. RP_CURRENT_LEVEL_NONE = 0,
  47. RP_CURRENT_LEVEL_DEFAULT,
  48. RP_CURRENT_LEVEL2,
  49. RP_CURRENT_LEVEL3,
  50. RP_CURRENT_ABNORMAL,
  51. } RP_CURRENT_LEVEL;
  52. typedef enum
  53. {
  54. FPDO_TYPE = 0,
  55. APDO_TYPE,
  56. VPDO_TYPE,
  57. } PDO_TYPE_T;
  58. typedef enum {
  59. AUTH_NONE = 0,
  60. AUTH_LOW_PWR,
  61. AUTH_HIGH_PWR,
  62. } AUTH_TYPE_T;
  63. typedef struct _power_list {
  64. int accept;
  65. int max_voltage;
  66. int min_voltage;
  67. int max_current;
  68. int pdo_type;
  69. int apdo;
  70. int comm_capable;
  71. int suspend;
  72. } POWER_LIST;
  73. typedef struct sec_pd_sink_status
  74. {
  75. POWER_LIST power_list[MAX_PDO_NUM+1];
  76. int has_apdo; // pd source has apdo or not
  77. int has_vpdo;
  78. int available_pdo_num; // the number of available PDO
  79. int selected_pdo_num; // selected number of PDO to change
  80. int current_pdo_num; // current number of PDO
  81. unsigned short vid;
  82. unsigned short pid;
  83. unsigned int xid;
  84. int pps_voltage;
  85. int pps_current;
  86. unsigned int rp_currentlvl; // rp current level by ccic
  87. void (*fp_sec_pd_select_pdo)(int num);
  88. int (*fp_sec_pd_select_pps)(int num, int ppsVol, int ppsCur);
  89. void (*fp_sec_pd_vpdo_auth)(int auth, int d2d_type);
  90. void (*fp_sec_pd_ext_cb)(unsigned short v_id, unsigned short p_id);
  91. void (*fp_sec_pd_manual_ccopen_req)(int is_on);
  92. void (*fp_sec_pd_manual_jig_ctrl)(bool mode);
  93. void (*fp_sec_pd_detach_with_cc)(int state);
  94. void (*fp_sec_pd_change_src)(int max_cur);
  95. } SEC_PD_SINK_STATUS;
  96. struct pdic_notifier_struct {
  97. pdic_notifier_event_t event;
  98. SEC_PD_SINK_STATUS sink_status;
  99. void *pusbpd;
  100. };
  101. #if IS_ENABLED(CONFIG_SEC_PD)
  102. const char* sec_pd_pdo_type_str(int pdo_type);
  103. int sec_pd_select_pdo(int num);
  104. int sec_pd_select_pps(int num, int ppsVol, int ppsCur);
  105. int sec_pd_vpdo_auth(int auth, int d2d_type);
  106. int sec_pd_get_current_pdo(unsigned int *pdo);
  107. int sec_pd_get_selected_pdo(unsigned int *pdo);
  108. int sec_pd_is_apdo(unsigned int pdo);
  109. int sec_pd_get_apdo_prog_volt(unsigned int pdo_type, unsigned int max_volt);
  110. int sec_pd_get_max_power(unsigned int pdo_type, unsigned int min_volt, unsigned int max_volt, unsigned int max_curr);
  111. int sec_pd_get_pdo_power(unsigned int *pdo, unsigned int *min_volt, unsigned int *max_volt, unsigned int *curr);
  112. int sec_pd_get_apdo_max_power(unsigned int *pdo_pos, unsigned int *taMaxVol, unsigned int *taMaxCur, unsigned int *taMaxPwr);
  113. void sec_pd_init_data(SEC_PD_SINK_STATUS* psink_status);
  114. int sec_pd_register_chg_info_cb(void *cb);
  115. int sec_pd_get_chg_info(void);
  116. void sec_pd_get_vid_pid(unsigned short *vid, unsigned short *pid, unsigned int *xid);
  117. void sec_pd_manual_ccopen_req(int is_on);
  118. void sec_pd_manual_jig_ctrl(bool mode);
  119. int sec_pd_detach_with_cc(int state);
  120. int sec_pd_change_src(int max_cur);
  121. #else
  122. static inline char* sec_pd_pdo_type_str(int pdo_type) { return "\0"; }
  123. static inline int sec_pd_select_pdo(int num) { return -ENODEV; }
  124. static inline int sec_pd_select_pps(int num, int ppsVol, int ppsCur) { return -ENODEV; }
  125. static inline int sec_pd_vpdo_auth(int auth, int d2d_type) { return -ENODEV; }
  126. static inline int sec_pd_get_current_pdo(unsigned int *pdo) { return -ENODEV; }
  127. static inline int sec_pd_get_selected_pdo(unsigned int *pdo) { return -ENODEV; }
  128. static inline int sec_pd_is_apdo(unsigned int pdo) { return -ENODEV; }
  129. static inline int sec_pd_get_apdo_prog_volt(unsigned int pdo_type, unsigned int max_volt) { return -ENODEV; }
  130. static inline int sec_pd_get_max_power(unsigned int pdo_type, unsigned int min_volt, unsigned int max_volt, unsigned int max_curr) { return -ENODEV; }
  131. static inline int sec_pd_get_pdo_power(unsigned int *pdo, unsigned int *min_volt, unsigned int *max_volt, unsigned int *curr) { return -ENODEV; }
  132. static inline int sec_pd_get_apdo_max_power(unsigned int *pdo_pos, unsigned int *taMaxVol, unsigned int *taMaxCur, unsigned int *taMaxPwr) { return -ENODEV; }
  133. static inline void sec_pd_init_data(SEC_PD_SINK_STATUS* psink_status) { }
  134. static inline int sec_pd_register_chg_info_cb(void *cb) { return 0; }
  135. static inline void sec_pd_get_vid_pid(unsigned short *vid, unsigned short *pid, unsigned int *xid) { }
  136. static inline void sec_pd_manual_ccopen_req(int is_on) { }
  137. static inline void sec_pd_manual_jig_ctrl(bool mode) { }
  138. static inline int sec_pd_detach_with_cc(int state) { return 0; }
  139. static inline int sec_pd_change_src(int max_cur) { return 0; }
  140. #endif
  141. #endif /* __SEC_PD_H__ */