wcd-clsh.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019,, 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _WCD_CLSH
  6. #define _WCD_CLSH
  7. #include <linux/stringify.h>
  8. #define WCD_CLSH_STRINGIFY(s) __stringify(s)
  9. #define CLSH_REQ_ENABLE true
  10. #define CLSH_REQ_DISABLE false
  11. #define WCD_CLSH_EVENT_PRE_DAC 0x01
  12. #define WCD_CLSH_EVENT_POST_PA 0x02
  13. /*
  14. * Basic states for Class H state machine.
  15. * represented as a bit mask within a u8 data type
  16. * bit 0: EAR mode
  17. * bit 1: HPH Left mode
  18. * bit 2: HPH Right mode
  19. * bit 3: AUX mode
  20. */
  21. #define WCD_CLSH_STATE_IDLE 0x00
  22. #define WCD_CLSH_STATE_EAR (0x01 << 0)
  23. #define WCD_CLSH_STATE_HPHL (0x01 << 1)
  24. #define WCD_CLSH_STATE_HPHR (0x01 << 2)
  25. #define WCD_CLSH_STATE_AUX (0x01 << 3)
  26. /*
  27. * Though number of CLSH states is 4, max state should be 5
  28. * because state array index starts from 1.
  29. */
  30. #define WCD_CLSH_STATE_MAX 5
  31. #define NUM_CLSH_STATES (0x01 << WCD_CLSH_STATE_MAX)
  32. /* Derived State: Bits 1 and 2 should be set for Headphone stereo */
  33. #define WCD_CLSH_STATE_HPH_ST (WCD_CLSH_STATE_HPHL | \
  34. WCD_CLSH_STATE_HPHR)
  35. #define WCD_CLSH_STATE_HPHL_AUX (WCD_CLSH_STATE_HPHL | \
  36. WCD_CLSH_STATE_AUX)
  37. #define WCD_CLSH_STATE_HPHR_AUX (WCD_CLSH_STATE_HPHR | \
  38. WCD_CLSH_STATE_AUX)
  39. #define WCD_CLSH_STATE_HPH_ST_AUX (WCD_CLSH_STATE_HPH_ST | \
  40. WCD_CLSH_STATE_AUX)
  41. #define WCD_CLSH_STATE_EAR_AUX (WCD_CLSH_STATE_EAR | \
  42. WCD_CLSH_STATE_AUX)
  43. #define WCD_CLSH_STATE_HPHL_EAR (WCD_CLSH_STATE_HPHL | \
  44. WCD_CLSH_STATE_EAR)
  45. #define WCD_CLSH_STATE_HPHR_EAR (WCD_CLSH_STATE_HPHR | \
  46. WCD_CLSH_STATE_EAR)
  47. #define WCD_CLSH_STATE_HPH_ST_EAR (WCD_CLSH_STATE_HPH_ST | \
  48. WCD_CLSH_STATE_EAR)
  49. #define WCD9XXX_BASE_ADDRESS 0x3000
  50. #define WCD9XXX_ANA_RX_SUPPLIES (WCD9XXX_BASE_ADDRESS+0x008)
  51. #define WCD9XXX_ANA_HPH (WCD9XXX_BASE_ADDRESS+0x009)
  52. #define WCD9XXX_CLASSH_MODE_2 (WCD9XXX_BASE_ADDRESS+0x098)
  53. #define WCD9XXX_CLASSH_MODE_3 (WCD9XXX_BASE_ADDRESS+0x099)
  54. #define WCD9XXX_FLYBACK_VNEG_CTRL_1 (WCD9XXX_BASE_ADDRESS+0x0A5)
  55. #define WCD9XXX_FLYBACK_VNEG_CTRL_4 (WCD9XXX_BASE_ADDRESS+0x0A8)
  56. #define WCD9XXX_FLYBACK_VNEGDAC_CTRL_2 (WCD9XXX_BASE_ADDRESS+0x0AF)
  57. #define WCD9XXX_RX_BIAS_HPH_LOWPOWER (WCD9XXX_BASE_ADDRESS+0x0BF)
  58. #define WCD9XXX_RX_BIAS_FLYB_BUFF (WCD9XXX_BASE_ADDRESS+0x0C7)
  59. #define WCD9XXX_HPH_PA_CTL1 (WCD9XXX_BASE_ADDRESS+0x0D1)
  60. #define WCD9XXX_HPH_NEW_INT_PA_MISC2 (WCD9XXX_BASE_ADDRESS+0x138)
  61. enum {
  62. CLS_H_NORMAL = 0, /* Class-H Default */
  63. CLS_H_HIFI, /* Class-H HiFi */
  64. CLS_H_LP, /* Class-H Low Power */
  65. CLS_AB, /* Class-AB Low HIFI*/
  66. CLS_H_LOHIFI, /* LoHIFI */
  67. CLS_H_ULP, /* Ultra Low power */
  68. CLS_AB_HIFI, /* Class-AB */
  69. CLS_AB_LP, /* Class-AB Low Power */
  70. CLS_AB_LOHIFI, /* Class-AB Low HIFI */
  71. CLS_NONE, /* None of the above modes */
  72. };
  73. /* Class H data that the codec driver will maintain */
  74. struct wcd_clsh_cdc_info {
  75. u8 state;
  76. int flyback_users;
  77. int buck_users;
  78. int interpolator_modes[WCD_CLSH_STATE_MAX];
  79. };
  80. #ifdef CONFIG_SND_SOC_WCD9XXX_V2
  81. extern void wcd_cls_h_fsm(struct snd_soc_component *component,
  82. struct wcd_clsh_cdc_info *cdc_clsh_d,
  83. u8 clsh_event, u8 req_state,
  84. int int_mode);
  85. extern void wcd_cls_h_init(struct wcd_clsh_cdc_info *clsh);
  86. extern void wcd_clsh_set_hph_mode(struct snd_soc_component *component,
  87. int mode);
  88. #else
  89. static inline void wcd_cls_h_fsm(struct snd_soc_component *component,
  90. struct wcd_clsh_cdc_info *cdc_clsh_d,
  91. u8 clsh_event, u8 req_state,
  92. int int_mode)
  93. {
  94. }
  95. static inline extern void wcd_cls_h_init(struct wcd_clsh_cdc_info *clsh)
  96. {
  97. }
  98. static inline extern void wcd_clsh_set_hph_mode(struct snd_soc_component *component,
  99. int mode)
  100. {
  101. }
  102. #endif /* CONFIG_SND_SOC_WCD9XXX_V2 */
  103. #endif