sb_vote.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * sb_vote.h
  3. * Samsung Mobile Battery Vote Header
  4. *
  5. * Copyright (C) 2021 Samsung Electronics, Inc.
  6. *
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef __SB_VOTE_H
  19. #define __SB_VOTE_H __FILE__
  20. #include <linux/err.h>
  21. #include <linux/battery/sb_def.h>
  22. enum {
  23. SB_VOTE_MIN,
  24. SB_VOTE_MAX,
  25. SB_VOTE_EN,
  26. SB_VOTE_DATA,
  27. };
  28. enum {
  29. VOTE_PRI_0 = 0,
  30. VOTE_PRI_1,
  31. VOTE_PRI_2,
  32. VOTE_PRI_3,
  33. VOTE_PRI_4,
  34. VOTE_PRI_5,
  35. VOTE_PRI_6,
  36. VOTE_PRI_7,
  37. VOTE_PRI_8,
  38. VOTE_PRI_9,
  39. VOTE_PRI_10,
  40. };
  41. #define VOTE_PRI_MIN VOTE_PRI_0
  42. #define VOTE_PRI_MAX VOTE_PRI_10
  43. struct sb_vote;
  44. typedef int (*cb_vote)(void *pdata, sb_data vdata);
  45. typedef bool (*cmp_vote)(sb_data *vdata1, sb_data *vdata2);
  46. struct sb_vote_cfg {
  47. const char *name;
  48. int type;
  49. const char **voter_list;
  50. int voter_num;
  51. cb_vote cb;
  52. cmp_vote cmp;
  53. };
  54. #define SB_VOTE_DISABLE (-3663)
  55. #define SB_VOTE_DISABLE_STR "voteoff"
  56. #if IS_ENABLED(CONFIG_SB_VOTE)
  57. struct sb_vote *sb_vote_create(const struct sb_vote_cfg *vote_cfg, void *pdata, sb_data init_data);
  58. void sb_vote_destroy(struct sb_vote *vote);
  59. struct sb_vote *sb_vote_find(const char *name);
  60. int sb_vote_get(struct sb_vote *vote, int event, sb_data *data);
  61. int sb_vote_get_result(struct sb_vote *vote, sb_data *data);
  62. int _sb_vote_set(struct sb_vote *vote, int event, bool en, sb_data data, const char *fname, int line);
  63. int sb_vote_set_pri(struct sb_vote *vote, int event, int pri);
  64. int sb_vote_refresh(struct sb_vote *vote);
  65. #else
  66. static inline struct sb_vote *sb_vote_create(const struct sb_vote_cfg *vote_cfg, void *pdata, sb_data init_data)
  67. { return ERR_PTR(SB_VOTE_DISABLE); }
  68. static inline void sb_vote_destroy(struct sb_vote *vote) {}
  69. static inline struct sb_vote *sb_vote_find(const char *name)
  70. { return ERR_PTR(SB_VOTE_DISABLE); }
  71. static inline int sb_vote_get(struct sb_vote *vote, int event, sb_data *data)
  72. { return SB_VOTE_DISABLE; }
  73. static inline int sb_vote_get_result(struct sb_vote *vote, sb_data *data)
  74. { return SB_VOTE_DISABLE; }
  75. static inline int _sb_vote_set(struct sb_vote *vote, int event, bool en, sb_data data, const char *fname, int linee)
  76. { return SB_VOTE_DISABLE; }
  77. static inline int sb_vote_set_pri(struct sb_vote *vote, int event, int pri)
  78. { return SB_VOTE_DISABLE; }
  79. static inline int sb_vote_refresh(struct sb_vote *vote)
  80. { return SB_VOTE_DISABLE; }
  81. #endif
  82. #define sb_vote_set(vote, event, en, value) _sb_vote_set(vote, event, en, value, __func__, __LINE__)
  83. #endif /* __SB_VOTE_H */