muic_param.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. *
  3. * Copyright (C) 2021 Samsung Electronics
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #define pr_fmt(fmt) "muic_param: " fmt
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/slab.h>
  23. #include <linux/muic/common/muic_param.h>
  24. static int muic_param_pmic_info = -1;
  25. module_param(muic_param_pmic_info, int, 0444);
  26. static int muic_param_uart_sel = -1;
  27. module_param(muic_param_uart_sel, int, 0444);
  28. static int muic_param_afc_mode = -1;
  29. module_param(muic_param_afc_mode, int, 0444);
  30. static int muic_param_pdic_info = -1;
  31. module_param(muic_param_pdic_info, int, 0444);
  32. #if ((IS_MODULE(CONFIG_SEC_PARAM) || IS_ENABLED(CONFIG_SEC_MPARAM)) && !IS_ENABLED(CONFIG_MUIC_USE_MODULE_PARAM))
  33. extern int pmic_info;
  34. extern unsigned int charging_mode;
  35. extern int ccic_info;
  36. #else
  37. static int pmic_info = -1;
  38. static unsigned int charging_mode;
  39. static int ccic_info = 1;
  40. #endif
  41. #if IS_BUILTIN(CONFIG_MUIC_NOTIFIER)
  42. static int __init set_switch_sel(char *str)
  43. {
  44. get_option(&str, &muic_param_pmic_info);
  45. pr_info("%s: pmic_info 0x%x\n", __func__, muic_param_pmic_info);
  46. return 1;
  47. }
  48. __setup("pmic_info=", set_switch_sel);
  49. /* func : set_uart_sel for QC boot command
  50. * uart_sel value get from bootloader command line
  51. */
  52. static int __init set_uart_sel(char *str)
  53. {
  54. get_option(&str, &muic_param_uart_sel);
  55. pr_info("%s: uart_sel is 0x%02x\n", __func__, muic_param_uart_sel);
  56. return 0;
  57. }
  58. early_param("uart_sel", set_uart_sel);
  59. /* afc_mode:
  60. * 0x31 : Disabled
  61. * 0x30 : Enabled
  62. */
  63. /* for LSI boot command */
  64. static int __init set_charging_mode(char *str)
  65. {
  66. int mode;
  67. get_option(&str, &mode);
  68. muic_param_afc_mode = (mode & 0x0000FF00) >> 8;
  69. pr_info("%s: afc_mode is 0x%02x\n", __func__, muic_param_afc_mode);
  70. return 0;
  71. }
  72. early_param("charging_mode", set_charging_mode);
  73. /* for QC boot command */
  74. static int __init set_afc_disable(char *str)
  75. {
  76. get_option(&str, &muic_param_afc_mode);
  77. pr_info("%s: afc_mode is 0x%02x\n", __func__, muic_param_afc_mode);
  78. return 0;
  79. }
  80. early_param("afc_disable", set_afc_disable);
  81. /*
  82. * __pdic_info :
  83. * b'0: 1 if an active pdic is present,
  84. * 0 when muic works without pdic chip or
  85. * no pdic Noti. registration is needed
  86. * even though a pdic chip is present.
  87. */
  88. static int __init set_pdic_info(char *str)
  89. {
  90. get_option(&str, &muic_param_pdic_info);
  91. pr_info("%s: pdic_info: 0x%04x\n", __func__, muic_param_pdic_info);
  92. return 1;
  93. }
  94. __setup("ccic_info=", set_pdic_info);
  95. #endif /* BUILTIN CONFIG_MUIC_NOTIFIER */
  96. /*
  97. * switch_sel value get from bootloader command line
  98. * switch_sel data consist 8 bits (xxxxyyyyzzzz)
  99. * first 4bits(zzzz) mean path information.
  100. * next 4bits(yyyy) mean if pmic version info
  101. * next 4bits(xxxx) mean afc disable info
  102. */
  103. int get_switch_sel(void)
  104. {
  105. int local_pmic_info = 0, local_switch_sel = 0;
  106. if (muic_param_pmic_info != -1) {
  107. local_pmic_info = muic_param_pmic_info;
  108. goto out;
  109. }
  110. local_pmic_info = pmic_info;
  111. out:
  112. local_switch_sel = local_pmic_info & 0xfff;
  113. pr_info("%s: switch_sel: 0x%03x\n", __func__, local_switch_sel);
  114. return local_switch_sel;
  115. }
  116. EXPORT_SYMBOL_GPL(get_switch_sel);
  117. int get_uart_sel(void)
  118. {
  119. int local_uart_sel = -1;
  120. if (muic_param_uart_sel != -1) {
  121. local_uart_sel = muic_param_uart_sel;
  122. goto out;
  123. }
  124. out:
  125. pr_info("%s: get_uart_sel 0x%x\n", __func__, local_uart_sel);
  126. return local_uart_sel;
  127. }
  128. EXPORT_SYMBOL_GPL(get_uart_sel);
  129. int get_afc_mode(void)
  130. {
  131. int local_afc_mode = 0, local_charging_mode = 0;
  132. if (muic_param_afc_mode != -1) {
  133. local_afc_mode = muic_param_afc_mode;
  134. goto out;
  135. }
  136. local_charging_mode = charging_mode;
  137. local_afc_mode = (local_charging_mode & 0x0000FF00) >> 8;
  138. out:
  139. pr_info("%s: afc_mode is 0x%02x\n", __func__, local_afc_mode);
  140. return local_afc_mode;
  141. }
  142. EXPORT_SYMBOL_GPL(get_afc_mode);
  143. int get_pdic_info(void)
  144. {
  145. int local_pdic_info = 1;
  146. if (muic_param_pdic_info != -1) {
  147. local_pdic_info = muic_param_pdic_info;
  148. goto out;
  149. }
  150. local_pdic_info = ccic_info;
  151. out:
  152. pr_info("%s: ccic_info: 0x%04x\n", __func__, local_pdic_info);
  153. return local_pdic_info;
  154. }
  155. EXPORT_SYMBOL_GPL(get_pdic_info);