wsa881x-regmap.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/regmap.h>
  14. #include <linux/device.h>
  15. #include "wsa881x-registers.h"
  16. #include "wsa881x.h"
  17. /*
  18. * Default register reset values that are common across different versions
  19. * are defined here. If a register reset value is changed based on version
  20. * then remove it from this structure and add it in version specific
  21. * structures.
  22. */
  23. static struct reg_default wsa881x_defaults[] = {
  24. {WSA881X_CHIP_ID0, 0x00},
  25. {WSA881X_CHIP_ID1, 0x00},
  26. {WSA881X_CHIP_ID2, 0x00},
  27. {WSA881X_CHIP_ID3, 0x02},
  28. {WSA881X_BUS_ID, 0x00},
  29. {WSA881X_CDC_RST_CTL, 0x00},
  30. {WSA881X_CDC_TOP_CLK_CTL, 0x03},
  31. {WSA881X_CDC_ANA_CLK_CTL, 0x00},
  32. {WSA881X_CDC_DIG_CLK_CTL, 0x00},
  33. {WSA881X_CLOCK_CONFIG, 0x00},
  34. {WSA881X_ANA_CTL, 0x08},
  35. {WSA881X_SWR_RESET_EN, 0x00},
  36. {WSA881X_TEMP_DETECT_CTL, 0x01},
  37. {WSA881X_TEMP_MSB, 0x00},
  38. {WSA881X_TEMP_LSB, 0x00},
  39. {WSA881X_TEMP_CONFIG0, 0x00},
  40. {WSA881X_TEMP_CONFIG1, 0x00},
  41. {WSA881X_CDC_CLIP_CTL, 0x03},
  42. {WSA881X_SDM_PDM9_LSB, 0x00},
  43. {WSA881X_SDM_PDM9_MSB, 0x00},
  44. {WSA881X_CDC_RX_CTL, 0x7E},
  45. {WSA881X_DEM_BYPASS_DATA0, 0x00},
  46. {WSA881X_DEM_BYPASS_DATA1, 0x00},
  47. {WSA881X_DEM_BYPASS_DATA2, 0x00},
  48. {WSA881X_DEM_BYPASS_DATA3, 0x00},
  49. {WSA881X_OTP_CTRL0, 0x00},
  50. {WSA881X_OTP_CTRL1, 0x00},
  51. {WSA881X_HDRIVE_CTL_GROUP1, 0x00},
  52. {WSA881X_INTR_MODE, 0x00},
  53. {WSA881X_INTR_STATUS, 0x00},
  54. {WSA881X_INTR_CLEAR, 0x00},
  55. {WSA881X_INTR_LEVEL, 0x00},
  56. {WSA881X_INTR_SET, 0x00},
  57. {WSA881X_INTR_TEST, 0x00},
  58. {WSA881X_PDM_TEST_MODE, 0x00},
  59. {WSA881X_ATE_TEST_MODE, 0x00},
  60. {WSA881X_PIN_CTL_MODE, 0x00},
  61. {WSA881X_PIN_CTL_OE, 0x00},
  62. {WSA881X_PIN_WDATA_IOPAD, 0x00},
  63. {WSA881X_PIN_STATUS, 0x00},
  64. {WSA881X_DIG_DEBUG_MODE, 0x00},
  65. {WSA881X_DIG_DEBUG_SEL, 0x00},
  66. {WSA881X_DIG_DEBUG_EN, 0x00},
  67. {WSA881X_SWR_HM_TEST1, 0x08},
  68. {WSA881X_SWR_HM_TEST2, 0x00},
  69. {WSA881X_TEMP_DETECT_DBG_CTL, 0x00},
  70. {WSA881X_TEMP_DEBUG_MSB, 0x00},
  71. {WSA881X_TEMP_DEBUG_LSB, 0x00},
  72. {WSA881X_SAMPLE_EDGE_SEL, 0x0C},
  73. {WSA881X_SPARE_0, 0x00},
  74. {WSA881X_SPARE_1, 0x00},
  75. {WSA881X_SPARE_2, 0x00},
  76. {WSA881X_OTP_REG_0, 0x01},
  77. {WSA881X_OTP_REG_1, 0xFF},
  78. {WSA881X_OTP_REG_2, 0xC0},
  79. {WSA881X_OTP_REG_3, 0xFF},
  80. {WSA881X_OTP_REG_4, 0xC0},
  81. {WSA881X_OTP_REG_5, 0xFF},
  82. {WSA881X_OTP_REG_6, 0xFF},
  83. {WSA881X_OTP_REG_7, 0xFF},
  84. {WSA881X_OTP_REG_8, 0xFF},
  85. {WSA881X_OTP_REG_9, 0xFF},
  86. {WSA881X_OTP_REG_10, 0xFF},
  87. {WSA881X_OTP_REG_11, 0xFF},
  88. {WSA881X_OTP_REG_12, 0xFF},
  89. {WSA881X_OTP_REG_13, 0xFF},
  90. {WSA881X_OTP_REG_14, 0xFF},
  91. {WSA881X_OTP_REG_15, 0xFF},
  92. {WSA881X_OTP_REG_16, 0xFF},
  93. {WSA881X_OTP_REG_17, 0xFF},
  94. {WSA881X_OTP_REG_18, 0xFF},
  95. {WSA881X_OTP_REG_19, 0xFF},
  96. {WSA881X_OTP_REG_20, 0xFF},
  97. {WSA881X_OTP_REG_21, 0xFF},
  98. {WSA881X_OTP_REG_22, 0xFF},
  99. {WSA881X_OTP_REG_23, 0xFF},
  100. {WSA881X_OTP_REG_24, 0x03},
  101. {WSA881X_OTP_REG_25, 0x01},
  102. {WSA881X_OTP_REG_26, 0x03},
  103. {WSA881X_OTP_REG_27, 0x11},
  104. {WSA881X_OTP_REG_63, 0x40},
  105. /* WSA881x Analog registers */
  106. {WSA881X_BIAS_REF_CTRL, 0x6C},
  107. {WSA881X_BIAS_TEST, 0x16},
  108. {WSA881X_BIAS_BIAS, 0xF0},
  109. {WSA881X_TEMP_OP, 0x00},
  110. {WSA881X_TEMP_IREF_CTRL, 0x56},
  111. {WSA881X_TEMP_ISENS_CTRL, 0x47},
  112. {WSA881X_TEMP_CLK_CTRL, 0x87},
  113. {WSA881X_TEMP_TEST, 0x00},
  114. {WSA881X_TEMP_BIAS, 0x51},
  115. {WSA881X_TEMP_DOUT_MSB, 0x00},
  116. {WSA881X_TEMP_DOUT_LSB, 0x00},
  117. {WSA881X_ADC_EN_MODU_V, 0x00},
  118. {WSA881X_ADC_EN_MODU_I, 0x00},
  119. {WSA881X_ADC_EN_DET_TEST_V, 0x00},
  120. {WSA881X_ADC_EN_DET_TEST_I, 0x00},
  121. {WSA881X_ADC_EN_SEL_IBAIS, 0x10},
  122. {WSA881X_SPKR_DRV_EN, 0x74},
  123. {WSA881X_SPKR_DRV_DBG, 0x15},
  124. {WSA881X_SPKR_PWRSTG_DBG, 0x00},
  125. {WSA881X_SPKR_OCP_CTL, 0xD4},
  126. {WSA881X_SPKR_CLIP_CTL, 0x90},
  127. {WSA881X_SPKR_PA_INT, 0x54},
  128. {WSA881X_SPKR_BIAS_CAL, 0xAC},
  129. {WSA881X_SPKR_STATUS1, 0x00},
  130. {WSA881X_SPKR_STATUS2, 0x00},
  131. {WSA881X_BOOST_EN_CTL, 0x18},
  132. {WSA881X_BOOST_CURRENT_LIMIT, 0x7A},
  133. {WSA881X_BOOST_PRESET_OUT2, 0x70},
  134. {WSA881X_BOOST_FORCE_OUT, 0x0E},
  135. {WSA881X_BOOST_LDO_PROG, 0x16},
  136. {WSA881X_BOOST_SLOPE_COMP_ISENSE_FB, 0x71},
  137. {WSA881X_BOOST_RON_CTL, 0x0F},
  138. {WSA881X_BOOST_ZX_CTL, 0x34},
  139. {WSA881X_BOOST_START_CTL, 0x23},
  140. {WSA881X_BOOST_MISC1_CTL, 0x80},
  141. {WSA881X_BOOST_MISC2_CTL, 0x00},
  142. {WSA881X_BOOST_MISC3_CTL, 0x00},
  143. {WSA881X_BOOST_ATEST_CTL, 0x00},
  144. {WSA881X_SPKR_PROT_FE_GAIN, 0x46},
  145. {WSA881X_SPKR_PROT_FE_CM_LDO_SET, 0x3B},
  146. {WSA881X_SPKR_PROT_FE_ISENSE_BIAS_SET1, 0x8D},
  147. {WSA881X_SPKR_PROT_FE_ISENSE_BIAS_SET2, 0x8D},
  148. {WSA881X_SPKR_PROT_ATEST1, 0x01},
  149. {WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x8D},
  150. {WSA881X_SPKR_PROT_FE_VSENSE_BIAS_SET1, 0x4D},
  151. {WSA881X_SPKR_PROT_SAR, 0x00},
  152. {WSA881X_SPKR_STATUS3, 0x00},
  153. };
  154. /* Default register reset values for WSA881x rev 2.0 */
  155. static struct reg_sequence wsa881x_rev_2_0[] = {
  156. {WSA881X_RESET_CTL, 0x00, 0x00},
  157. {WSA881X_TADC_VALUE_CTL, 0x01, 0x00},
  158. {WSA881X_INTR_MASK, 0x1B, 0x00},
  159. {WSA881X_IOPAD_CTL, 0x00, 0x00},
  160. {WSA881X_OTP_REG_28, 0x3F, 0x00},
  161. {WSA881X_OTP_REG_29, 0x3F, 0x00},
  162. {WSA881X_OTP_REG_30, 0x01, 0x00},
  163. {WSA881X_OTP_REG_31, 0x01, 0x00},
  164. {WSA881X_TEMP_ADC_CTRL, 0x03, 0x00},
  165. {WSA881X_ADC_SEL_IBIAS, 0x45, 0x00},
  166. {WSA881X_SPKR_DRV_GAIN, 0xC1, 0x00},
  167. {WSA881X_SPKR_DAC_CTL, 0x42, 0x00},
  168. {WSA881X_SPKR_BBM_CTL, 0x02, 0x00},
  169. {WSA881X_SPKR_MISC_CTL1, 0x40, 0x00},
  170. {WSA881X_SPKR_MISC_CTL2, 0x07, 0x00},
  171. {WSA881X_SPKR_BIAS_INT, 0x5F, 0x00},
  172. {WSA881X_SPKR_BIAS_PSRR, 0x44, 0x00},
  173. {WSA881X_BOOST_PS_CTL, 0xA0, 0x00},
  174. {WSA881X_BOOST_PRESET_OUT1, 0xB7, 0x00},
  175. {WSA881X_BOOST_LOOP_STABILITY, 0x8D, 0x00},
  176. {WSA881X_SPKR_PROT_ATEST2, 0x02, 0x00},
  177. {WSA881X_BONGO_RESRV_REG1, 0x5E, 0x00},
  178. {WSA881X_BONGO_RESRV_REG2, 0x07, 0x00},
  179. };
  180. /*
  181. * wsa881x_regmap_defaults - update regmap default register values
  182. * @regmap: pointer to regmap structure
  183. * @version: wsa881x version id
  184. *
  185. * Update regmap default register values based on version id
  186. *
  187. */
  188. void wsa881x_regmap_defaults(struct regmap *regmap, u8 version)
  189. {
  190. u16 ret = 0;
  191. if (!regmap) {
  192. pr_debug("%s: regmap structure is NULL\n", __func__);
  193. return;
  194. }
  195. regcache_cache_only(regmap, true);
  196. ret = regmap_multi_reg_write(regmap, wsa881x_rev_2_0,
  197. ARRAY_SIZE(wsa881x_rev_2_0));
  198. regcache_cache_only(regmap, false);
  199. if (ret)
  200. pr_debug("%s: Failed to update regmap defaults ret= %d\n",
  201. __func__, ret);
  202. }
  203. EXPORT_SYMBOL(wsa881x_regmap_defaults);
  204. static bool wsa881x_readable_register(struct device *dev, unsigned int reg)
  205. {
  206. return wsa881x_reg_readable[reg];
  207. }
  208. static bool wsa881x_volatile_register(struct device *dev, unsigned int reg)
  209. {
  210. switch (reg) {
  211. case WSA881X_CHIP_ID0:
  212. case WSA881X_CHIP_ID1:
  213. case WSA881X_CHIP_ID2:
  214. case WSA881X_CHIP_ID3:
  215. case WSA881X_BUS_ID:
  216. case WSA881X_TEMP_MSB:
  217. case WSA881X_TEMP_LSB:
  218. case WSA881X_SDM_PDM9_LSB:
  219. case WSA881X_SDM_PDM9_MSB:
  220. case WSA881X_OTP_CTRL1:
  221. case WSA881X_INTR_STATUS:
  222. case WSA881X_ATE_TEST_MODE:
  223. case WSA881X_PIN_STATUS:
  224. case WSA881X_SWR_HM_TEST2:
  225. case WSA881X_SPKR_STATUS1:
  226. case WSA881X_SPKR_STATUS2:
  227. case WSA881X_SPKR_STATUS3:
  228. case WSA881X_OTP_REG_0:
  229. case WSA881X_OTP_REG_1:
  230. case WSA881X_OTP_REG_2:
  231. case WSA881X_OTP_REG_3:
  232. case WSA881X_OTP_REG_4:
  233. case WSA881X_OTP_REG_5:
  234. case WSA881X_OTP_REG_31:
  235. case WSA881X_TEMP_DOUT_MSB:
  236. case WSA881X_TEMP_DOUT_LSB:
  237. case WSA881X_TEMP_OP:
  238. case WSA881X_SPKR_PROT_SAR:
  239. return true;
  240. default:
  241. return false;
  242. }
  243. }
  244. struct regmap_config wsa881x_regmap_config = {
  245. .reg_bits = 16,
  246. .val_bits = 8,
  247. .cache_type = REGCACHE_RBTREE,
  248. .reg_defaults = wsa881x_defaults,
  249. .num_reg_defaults = ARRAY_SIZE(wsa881x_defaults),
  250. .max_register = WSA881X_MAX_REGISTER,
  251. .volatile_reg = wsa881x_volatile_register,
  252. .readable_reg = wsa881x_readable_register,
  253. .reg_format_endian = REGMAP_ENDIAN_NATIVE,
  254. .val_format_endian = REGMAP_ENDIAN_NATIVE,
  255. .can_multi_write = true,
  256. };