drv_cs42l51.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Date Author Notes
  7. * 2020-07-02 thread-liu first version
  8. */
  9. #ifndef __DRV_CS42L51_H__
  10. #define __DRV_CS42L51_H__
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef struct
  15. {
  16. rt_err_t (*init)(uint16_t , const char *, uint8_t);
  17. void (*deinit)(void);
  18. uint32_t (*read_id)(void);
  19. uint32_t (*play)(void);
  20. uint32_t (*pause)(void);
  21. uint32_t (*resume)(void);
  22. uint32_t (*stop)(void);
  23. uint32_t (*set_frequency)(uint32_t);
  24. uint32_t (*set_volume)(uint8_t);
  25. uint32_t (*get_volume)(void);
  26. uint32_t (*set_mute)(uint32_t);
  27. uint32_t (*set_output_mode)(uint8_t);
  28. uint32_t (*reset)(void);
  29. }AUDIO_DrvTypeDef;
  30. extern AUDIO_DrvTypeDef cs42l51_drv;
  31. /* CS42L51 register space */
  32. #define CS42L51_CHIP_ID 0x1B
  33. #define CS42L51_CHIP_REV_A 0x00
  34. #define CS42L51_CHIP_REV_B 0x01
  35. #define CS42L51_CHIP_REV_ID 0x01
  36. #define CS42L51_MK_CHIP_REV(a, b) ((a)<<3|(b))
  37. #define CS42L51_POWER_CTL1 0x02
  38. #define CS42L51_POWER_CTL1_PDN_DACB (1<<6)
  39. #define CS42L51_POWER_CTL1_PDN_DACA (1<<5)
  40. #define CS42L51_POWER_CTL1_PDN_PGAB (1<<4)
  41. #define CS42L51_POWER_CTL1_PDN_PGAA (1<<3)
  42. #define CS42L51_POWER_CTL1_PDN_ADCB (1<<2)
  43. #define CS42L51_POWER_CTL1_PDN_ADCA (1<<1)
  44. #define CS42L51_POWER_CTL1_PDN (1<<0)
  45. #define CS42L51_MIC_POWER_CTL 0x03
  46. #define CS42L51_MIC_POWER_CTL_AUTO (1<<7)
  47. #define CS42L51_MIC_POWER_CTL_SPEED(x) (((x)&3)<<5)
  48. #define CS42L51_QSM_MODE 3
  49. #define CS42L51_HSM_MODE 2
  50. #define CS42L51_SSM_MODE 1
  51. #define CS42L51_DSM_MODE 0
  52. #define CS42L51_MIC_POWER_CTL_3ST_SP (1<<4)
  53. #define CS42L51_MIC_POWER_CTL_PDN_MICB (1<<3)
  54. #define CS42L51_MIC_POWER_CTL_PDN_MICA (1<<2)
  55. #define CS42L51_MIC_POWER_CTL_PDN_BIAS (1<<1)
  56. #define CS42L51_MIC_POWER_CTL_MCLK_DIV2 (1<<0)
  57. #define CS42L51_INTF_CTL 0x04
  58. #define CS42L51_INTF_CTL_LOOPBACK (1<<7)
  59. #define CS42L51_INTF_CTL_MASTER (1<<6)
  60. #define CS42L51_INTF_CTL_DAC_FORMAT(x) (((x)&7)<<3)
  61. #define CS42L51_DAC_DIF_LJ24 0x00
  62. #define CS42L51_DAC_DIF_I2S 0x01
  63. #define CS42L51_DAC_DIF_RJ24 0x02
  64. #define CS42L51_DAC_DIF_RJ20 0x03
  65. #define CS42L51_DAC_DIF_RJ18 0x04
  66. #define CS42L51_DAC_DIF_RJ16 0x05
  67. #define CS42L51_INTF_CTL_ADC_I2S (1<<2)
  68. #define CS42L51_INTF_CTL_DIGMIX (1<<1)
  69. #define CS42L51_INTF_CTL_MICMIX (1<<0)
  70. #define CS42L51_MIC_CTL 0x05
  71. #define CS42L51_MIC_CTL_ADC_SNGVOL (1<<7)
  72. #define CS42L51_MIC_CTL_ADCD_DBOOST (1<<6)
  73. #define CS42L51_MIC_CTL_ADCA_DBOOST (1<<5)
  74. #define CS42L51_MIC_CTL_MICBIAS_SEL (1<<4)
  75. #define CS42L51_MIC_CTL_MICBIAS_LVL(x) (((x)&3)<<2)
  76. #define CS42L51_MIC_CTL_MICB_BOOST (1<<1)
  77. #define CS42L51_MIC_CTL_MICA_BOOST (1<<0)
  78. #define CS42L51_ADC_CTL 0x06
  79. #define CS42L51_ADC_CTL_ADCB_HPFEN (1<<7)
  80. #define CS42L51_ADC_CTL_ADCB_HPFRZ (1<<6)
  81. #define CS42L51_ADC_CTL_ADCA_HPFEN (1<<5)
  82. #define CS42L51_ADC_CTL_ADCA_HPFRZ (1<<4)
  83. #define CS42L51_ADC_CTL_SOFTB (1<<3)
  84. #define CS42L51_ADC_CTL_ZCROSSB (1<<2)
  85. #define CS42L51_ADC_CTL_SOFTA (1<<1)
  86. #define CS42L51_ADC_CTL_ZCROSSA (1<<0)
  87. #define CS42L51_ADC_INPUT 0x07
  88. #define CS42L51_ADC_INPUT_AINB_MUX(x) (((x)&3)<<6)
  89. #define CS42L51_ADC_INPUT_AINA_MUX(x) (((x)&3)<<4)
  90. #define CS42L51_ADC_INPUT_INV_ADCB (1<<3)
  91. #define CS42L51_ADC_INPUT_INV_ADCA (1<<2)
  92. #define CS42L51_ADC_INPUT_ADCB_MUTE (1<<1)
  93. #define CS42L51_ADC_INPUT_ADCA_MUTE (1<<0)
  94. #define CS42L51_DAC_OUT_CTL 0x08
  95. #define CS42L51_DAC_OUT_CTL_HP_GAIN(x) (((x)&7)<<5)
  96. #define CS42L51_DAC_OUT_CTL_DAC_SNGVOL (1<<4)
  97. #define CS42L51_DAC_OUT_CTL_INV_PCMB (1<<3)
  98. #define CS42L51_DAC_OUT_CTL_INV_PCMA (1<<2)
  99. #define CS42L51_DAC_OUT_CTL_DACB_MUTE (1<<1)
  100. #define CS42L51_DAC_OUT_CTL_DACA_MUTE (1<<0)
  101. #define CS42L51_DAC_CTL 0x09
  102. #define CS42L51_DAC_CTL_DATA_SEL(x) (((x)&3)<<6)
  103. #define CS42L51_DAC_CTL_FREEZE (1<<5)
  104. #define CS42L51_DAC_CTL_DEEMPH (1<<3)
  105. #define CS42L51_DAC_CTL_AMUTE (1<<2)
  106. #define CS42L51_DAC_CTL_DACSZ(x) (((x)&3)<<0)
  107. #define CS42L51_ALC_PGA_CTL 0x0A
  108. #define CS42L51_ALC_PGB_CTL 0x0B
  109. #define CS42L51_ALC_PGX_ALCX_SRDIS (1<<7)
  110. #define CS42L51_ALC_PGX_ALCX_ZCDIS (1<<6)
  111. #define CS42L51_ALC_PGX_PGX_VOL(x) (((x)&0x1f)<<0)
  112. #define CS42L51_ADCA_ATT 0x0C
  113. #define CS42L51_ADCB_ATT 0x0D
  114. #define CS42L51_ADCA_VOL 0x0E
  115. #define CS42L51_ADCB_VOL 0x0F
  116. #define CS42L51_PCMA_VOL 0x10
  117. #define CS42L51_PCMB_VOL 0x11
  118. #define CS42L51_MIX_MUTE_ADCMIX (1<<7)
  119. #define CS42L51_MIX_VOLUME(x) (((x)&0x7f)<<0)
  120. #define CS42L51_BEEP_FREQ 0x12
  121. #define CS42L51_BEEP_VOL 0x13
  122. #define CS42L51_BEEP_CONF 0x14
  123. #define CS42L51_TONE_CTL 0x15
  124. #define CS42L51_TONE_CTL_TREB(x) (((x)&0xf)<<4)
  125. #define CS42L51_TONE_CTL_BASS(x) (((x)&0xf)<<0)
  126. #define CS42L51_AOUTA_VOL 0x16
  127. #define CS42L51_AOUTB_VOL 0x17
  128. #define CS42L51_PCM_MIXER 0x18
  129. #define CS42L51_LIMIT_THRES_DIS 0x19
  130. #define CS42L51_LIMIT_REL 0x1A
  131. #define CS42L51_LIMIT_ATT 0x1B
  132. #define CS42L51_ALC_EN 0x1C
  133. #define CS42L51_ALC_REL 0x1D
  134. #define CS42L51_ALC_THRES 0x1E
  135. #define CS42L51_NOISE_CONF 0x1F
  136. #define CS42L51_STATUS 0x20
  137. #define CS42L51_STATUS_SP_CLKERR (1<<6)
  138. #define CS42L51_STATUS_SPEA_OVFL (1<<5)
  139. #define CS42L51_STATUS_SPEB_OVFL (1<<4)
  140. #define CS42L51_STATUS_PCMA_OVFL (1<<3)
  141. #define CS42L51_STATUS_PCMB_OVFL (1<<2)
  142. #define CS42L51_STATUS_ADCA_OVFL (1<<1)
  143. #define CS42L51_STATUS_ADCB_OVFL (1<<0)
  144. #define CS42L51_CHARGE_FREQ 0x21
  145. #define CS42L51_FIRSTREG 0x01
  146. enum play_type {
  147. NONE,
  148. OUT_HEADPHONE,
  149. IN_MIC1,
  150. IN_MIC2,
  151. IN_LINE1,
  152. IN_LINE2,
  153. IN_LINE3,
  154. };
  155. /*
  156. * Hack: with register 0x21, it makes 33 registers. Looks like someone in the
  157. * i2c layer doesn't like i2c smbus block read of 33 regs. Workaround by using
  158. * 32 regs
  159. */
  160. #define CS42L51_LASTREG 0x20
  161. #define CS42L51_NUMREGS (CS42L51_LASTREG - CS42L51_FIRSTREG + 1)
  162. #define VOLUME_CONVERT(Volume) ((Volume >= 100) ? 0 : ((uint8_t)(((Volume * 2) + 56))))
  163. #define VOLUME_INVERT(Volume) (((Volume) == 0U) ? 100U : ((uint8_t)(((Volume) - 56U) / 2U)))
  164. /* MUTE commands */
  165. #define AUDIO_MUTE_ON 1
  166. #define AUDIO_MUTE_OFF 0
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif