es325.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * es325.h -- ES325 Soc Audio driver
  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 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef _ES325_H
  9. #define _ES325_H
  10. #include <sound/soc.h>
  11. #define ES325_READ_VE_OFFSET 0x0804
  12. #define ES325_READ_VE_WIDTH 4
  13. #define ES325_WRITE_VE_OFFSET 0x0800
  14. #define ES325_WRITE_VE_WIDTH 4
  15. #define ES325_MCLK_DIV 0x0000
  16. #define ES325_CLASSD_CLK_DIV 0x0001
  17. #define ES325_CP_CLK_DIV 0x0002
  18. #define ES325_BOOT_CMD 0x0001
  19. #define ES325_BOOT_ACK 0x01010101
  20. #define ES325_SYNC_CMD 0x8000
  21. #define ES325_SYNC_POLLING 0x0000
  22. #define ES325_SYNC_INTR_ACITVE_LOW 0x0001
  23. #define ES325_SYNC_INTR_ACITVE_HIGH 0x0002
  24. #define ES325_SYNC_INTR_FALLING_EDGE 0x0003
  25. #define ES325_SYNC_INTR_RISING_EDGE 0x0004
  26. #define ES325_SYNC_ACK 0x80000000
  27. #define ES325_RESET_CMD 0x8002
  28. #define ES325_RESET_IMMED 0x0000
  29. #define ES325_RESET_DELAYED 0x0001
  30. #define ES325_SET_POWER_STATE 0x8010
  31. #define ES325_POWER_STATE_SLEEP 0x0001
  32. #define ES325_POWER_STATE_NORMAL 0x0004
  33. #define ES325_POWER_STATE_VS_OVERLAY 0x0005
  34. #define ES325_POWER_STATE_VS_LOWPWR 0x0006
  35. #define ES325_POWER_STATE_SLEEP_PENDING 0x0007
  36. #define ES325_POWER_STATE_SLEEP_REQUESTED 0x0008
  37. #define ES325_SMOOTH_MUTE 0x904E0000
  38. /*
  39. * bit15 - reserved
  40. * bit[14:12] - access type
  41. * bit11 - commit = 0, staged = 1
  42. * bit[10:0] - psuedo address
  43. */
  44. #define ES325_ACCESS_MASK (7 << 12)
  45. #define ES325_ALGO_ACCESS (0 << 12)
  46. #define ES325_DEV_ACCESS (1 << 12)
  47. #define ES325_CMD_ACCESS (2 << 12)
  48. #define ES325_OTHER_ACCESS (3 << 12)
  49. #define ES325_CMD_MASK (1 << 11)
  50. #define ES325_STAGED_CMD (1 << 11)
  51. #define ES325_COMMIT_CMD (0 << 11)
  52. #define ES325_ADDR_MASK 0x7ff
  53. #define ES325_STAGED_MSG_BIT (1 << 13)
  54. /*
  55. * Device parameter command codes
  56. */
  57. #define ES325_DEV_PARAM_OFFSET 0x2000
  58. #define ES325_GET_DEV_PARAM 0x800b
  59. #define ES325_SET_DEV_PARAM_ID 0x900c
  60. #define ES325_SET_DEV_PARAM 0x900d
  61. /*
  62. * Algoithm parameter command codes
  63. */
  64. #define ES325_ALGO_PARAM_OFFSET 0x0000
  65. #define ES325_GET_ALGO_PARAM 0x8016
  66. #define ES325_SET_ALGO_PARAM_ID 0x9017
  67. #define ES325_SET_ALGO_PARAM 0x9018
  68. /* Speculative sleep delay in msecs */
  69. #define ES325_SLEEP_DELAY 300
  70. /*
  71. * addresses
  72. */
  73. enum {
  74. ES325_MIC_CONFIG,
  75. ES325_AEC_MODE,
  76. ES325_TX_AGC,
  77. ES325_TX_AGC_TARGET_LEVEL,
  78. ES325_TX_AGC_NOISE_FLOOR,
  79. ES325_TX_AGC_SNR_IMPROVEMENT,
  80. ES325_VEQ_ENABLE,
  81. ES325_RX_OUT_LIMITER_MAX_LEVEL,
  82. ES325_RX_NOISE_SUPPRESS,
  83. ES325_RX_STS,
  84. ES325_RX_STS_RATE,
  85. ES325_AEC_SPEAKER_VOLUME,
  86. ES325_SIDETONE,
  87. ES325_SIDETONE_GAIN,
  88. ES325_TX_COMFORT_NOISE,
  89. ES325_TX_COMFORT_NOISE_LEVEL,
  90. ES325_ALGORITHM_RESET,
  91. ES325_RX_POST_EQ,
  92. ES325_TX_POST_EQ,
  93. ES325_AEC_CNG,
  94. ES325_VEQ_NOISE_ESTIMATION_ADJUSTMENT,
  95. ES325_TX_AGC_SLEW_RATE_UP,
  96. ES325_TX_AGC_SLEW_RATE_DOWN,
  97. ES325_RX_AGC,
  98. ES325_RX_AGC_TARGET_LEVEL,
  99. ES325_RX_AGC_NOISE_FLOOR,
  100. ES325_RX_AGC_SNR_IMPROVEMENT,
  101. ES325_RX_AGC_SLEW_RATE_UP,
  102. ES325_RX_AGC_SLEW_RATE_DOWN,
  103. ES325_AEC_CNG_GAIN,
  104. ES325_TX_MBC,
  105. ES325_RX_MBC,
  106. ES325_AEC_ESE,
  107. ES325_TX_NS_ADAPTATION_SPEED,
  108. ES325_TX_SNR_ESTIMATE,
  109. ES325_VEQ_MAX_GAIN,
  110. ES325_TX_AGC_GUARDBAND,
  111. ES325_RX_AGC_GUARDBAND,
  112. ES325_TX_OUT_LIMITER_MAX_LEVEL,
  113. ES325_TX_IN_LIMITER_MAX_LEVEL,
  114. ES325_RX_NS_ADAPTATION_SPEED,
  115. ES325_AEC_VARIABLE_ECHO_REF_DELAY,
  116. ES325_TX_NOISE_SUPPRESS_LEVEL,
  117. ES325_RX_NOISE_SUPPRESS_LEVEL,
  118. ES325_RX_CNG,
  119. ES325_RX_CNG_GAIN,
  120. ES325_TX_AGC_MAX_GAIN,
  121. ES325_RX_AGC_MAX_GAIN,
  122. ES325_AVALON_API_VERSION_LO,
  123. ES325_AVALON_API_VERSION_HI,
  124. ES325_AVALON_AV_PROCESSOR,
  125. ES325_AVALON_AV_CONFIG,
  126. ES325_AVALON_EQ_PRESET,
  127. ES325_AVALON_STEREO_WIDTH,
  128. ES325_AVALON_AV_DIGITAL_OUT_GAIN,
  129. ES325_AVALON_TDMBC,
  130. ES325_AVALON_AV_OUT_LIMIT,
  131. ES325_AVALON_STEREO_WIDENING,
  132. ES325_AVALON_STAT_NS,
  133. ES325_AVALON_STAT_NS_SUPPRESS,
  134. ES325_AVALON_STAT_NS_ADAP_SPEED,
  135. ES325_AVALON_STAT_NS_MODE,
  136. ES325_AVLALON_STAT_NS_MAX_NOISE_ENERGY,
  137. ES325_AVALON_VBB,
  138. ES325_AVALON_VBB_STRENGTH,
  139. ES325_AVALON_EQ_MODE,
  140. ES325_AVALON_EQ_GRAPHIC_BAND1_GAIN,
  141. ES325_AVALON_EQ_GRAPHIC_BAND2_GAIN,
  142. ES325_AVALON_EQ_GRAPHIC_BAND3_GAIN,
  143. ES325_AVALON_EQ_GRAPHIC_BAND4_GAIN,
  144. ES325_AVALON_EQ_GRAPHIC_BAND5_GAIN,
  145. ES325_AVALON_EQ_GRAPHIC_BAND6_GAIN,
  146. ES325_AVALON_EQ_GRAPHIC_BAND7_GAIN,
  147. ES325_AVALON_EQ_GRAPHIC_BAND8_GAIN,
  148. ES325_AVALON_EQ_GRAPHIC_BAND9_GAIN,
  149. ES325_AVALON_EQ_GRAPHIC_BAND10_GAIN,
  150. ES325_AVALON_TDDRC,
  151. ES325_AVALON_TDDRC_STRENGTH,
  152. ES325_AVALON_LIMITER,
  153. ES325_AVALON_EQ,
  154. ES325_DIRAC,
  155. ES325_DIRAC_OUT_HEADROOM_LIMITER,
  156. ES325_DIRAC_MODE,
  157. ES325_DIRAC_IN_HEADROOM_LIMITER,
  158. ES325_DIRAC_COMFORT_NOISE,
  159. ES325_DIRAC_COMFORT_NOISE_LEVEL,
  160. ES325_DIRAC_NARRATOR_VQOS,
  161. ES325_DIRAC_NARRATOR_POSITION_SUPPRESS,
  162. ES325_DIRAC_NARRATOR_AGC_OUT,
  163. ES325_DIRAC_NARRATOR_AGC_SPEECH_TARGET,
  164. ES325_DIRAC_NARRATOR_AGC_SNR_IMPROVE,
  165. ES325_DIRAC_NARRATOR_AGC_NOISE_FLOOR,
  166. ES325_DIRAC_NARRATOR_AGC_MAX_GAIN,
  167. ES325_DIRAC_NARRATOR_AGC_UP_RATE,
  168. ES325_DIRAC_NARRATOR_AGC_DOWN_RATE,
  169. ES325_DIRAC_NARRATOR_AGC_GUARDBAND,
  170. ES325_DIRAC_NARRATOR_POST_EQ_MODE,
  171. ES325_DIRAC_NARRATOR_MBC_MODE,
  172. ES325_DIRAC_SCENE_BEAM_WIDTH,
  173. ES325_DIRAC_SCENE_AGC_OUT,
  174. ES325_DIRAC_SCENE_AGC_SPEECH_TARGET,
  175. ES325_DIRAC_SCENE_AGC_SNR_IMPROVE,
  176. ES325_DIRAC_SCENE_AGC_NOISE_FLOOR,
  177. ES325_DIRAC_SCENE_AGC_MAX_GAIN,
  178. ES325_DIRAC_SCENE_AGC_UP_RATE,
  179. ES325_DIRAC_SCENE_AGC_DOWN_RATE,
  180. ES325_DIRAC_SCENE_AGC_GUARDBAND,
  181. ES325_DIRAC_SCENE_VQOS,
  182. ES325_DIRAC_SCENE_POST_EQ_MODE,
  183. ES325_DIRAC_SCENE_MBC_MODE,
  184. ES325_TONE_PARAM_API_VERSION_LO,
  185. ES325_TONE_PARAM_API_VERSION_HI,
  186. ES325_TONE_PARAM_ENABLE_BEEP_SYS,
  187. ES325_TONE_PARAM_ENABLE_GEN_BEEP,
  188. ES325_TONE_PARAM_GEN_BEEP_ON,
  189. ES325_TONE_PARAM_GEN_BEEP_FREQ1,
  190. ES325_TONE_PARAM_GEN_BEEP_FREQ2,
  191. ES325_TONE_PARAM_GEN_BEEP_PAN_LR,
  192. ES325_TONE_PARAM_GEN_BEEP_GAIN,
  193. ES325_DEREVERB_ENABLE,
  194. ES325_DEREVERB_GAIN,
  195. ES325_BWE_ENABLE,
  196. ES325_BWE_HIGH_BAND_GAIN,
  197. ES325_BWE_MAX_SNR,
  198. ES325_BWE_POST_EQ_ENABLE,
  199. ES325_PORTA_WORD_LEN,
  200. ES325_PORTA_TDM_SLOTS_PER_FRAME,
  201. ES325_PORTA_TX_DELAY_FROM_FS,
  202. ES325_PORTA_RX_DELAY_FROM_FS,
  203. ES325_PORTA_LATCH_EDGE,
  204. ES325_PORTA_ENDIAN,
  205. ES325_PORTA_TRISTATE,
  206. ES325_PORTA_AUDIO_PORT_MODE,
  207. ES325_PORTA_TDM_ENABLED,
  208. ES325_PORTA_CLOCK_CONTROL,
  209. ES325_PORTA_DATA_JUSTIFICATION,
  210. ES325_PORTA_FS_DURATION,
  211. ES325_PORTB_WORD_LEN,
  212. ES325_PORTB_TDM_SLOTS_PER_FRAME,
  213. ES325_PORTB_TX_DELAY_FROM_FS,
  214. ES325_PORTB_RX_DELAY_FROM_FS,
  215. ES325_PORTB_LATCH_EDGE,
  216. ES325_PORTB_ENDIAN,
  217. ES325_PORTB_TRISTATE,
  218. ES325_PORTB_AUDIO_PORT_MODE,
  219. ES325_PORTB_TDM_ENABLED,
  220. ES325_PORTB_CLOCK_CONTROL,
  221. ES325_PORTB_DATA_JUSTIFICATION,
  222. ES325_PORTB_FS_DURATION,
  223. ES325_PORTC_WORD_LEN,
  224. ES325_PORTC_TDM_SLOTS_PER_FRAME,
  225. ES325_PORTC_TX_DELAY_FROM_FS,
  226. ES325_PORTC_RX_DELAY_FROM_FS,
  227. ES325_PORTC_LATCH_EDGE,
  228. ES325_PORTC_ENDIAN,
  229. ES325_PORTC_TRISTATE,
  230. ES325_PORTC_AUDIO_PORT_MODE,
  231. ES325_PORTC_TDM_ENABLED,
  232. ES325_PORTC_CLOCK_CONTROL,
  233. ES325_PORTC_DATA_JUSTIFICATION,
  234. ES325_PORTC_FS_DURATION,
  235. ES325_PORTD_WORD_LEN,
  236. ES325_PORTD_TDM_SLOTS_PER_FRAME,
  237. ES325_PORTD_TX_DELAY_FROM_FS,
  238. ES325_PORTD_RX_DELAY_FROM_FS,
  239. ES325_PORTD_LATCH_EDGE,
  240. ES325_PORTD_ENDIAN,
  241. ES325_PORTD_TRISTATE,
  242. ES325_PORTD_AUDIO_PORT_MODE,
  243. ES325_PORTD_TDM_ENABLED,
  244. ES325_PORTD_CLOCK_CONTROL,
  245. ES325_PORTD_DATA_JUSTIFICATION,
  246. ES325_PORTD_FS_DURATION,
  247. ES325_SLIMBUS_LINK_MULTI_CHANNEL,
  248. ES325_POWER_STATE,
  249. ES325_STREAMING,
  250. ES325_FE_STREAMING,
  251. ES325_PRESET,
  252. ES325_ALGO_STATS,
  253. ES325_ALGO_PROCESSING,
  254. ES325_ALGO_SAMPLE_RATE,
  255. ES325_SMOOTH_RATE,
  256. ES325_CHANGE_STATUS,
  257. ES325_DIGITAL_PASS_THROUGH,
  258. ES325_DATA_PATH,
  259. ES325_ALGORITHM,
  260. ES325_MIX_SAMPLE_RATE,
  261. ES325_SIGNAL_RMS_PORTA_DIN_LEFT,
  262. ES325_SIGNAL_RMS_PORTA_DIN_RIGHT,
  263. ES325_SIGNAL_RMS_PORTA_DOUT_LEFT,
  264. ES325_SIGNAL_RMS_PORTA_DOUT_RIGHT,
  265. ES325_SIGNAL_RMS_PORTB_DIN_LEFT,
  266. ES325_SIGNAL_RMS_PORTB_DIN_RIGHT,
  267. ES325_SIGNAL_RMS_PORTB_DOUT_LEFT,
  268. ES325_SIGNAL_RMS_PORTB_DOUT_RIGHT,
  269. ES325_SIGNAL_RMS_PORTC_DIN_LEFT,
  270. ES325_SIGNAL_RMS_PORTC_DIN_RIGHT,
  271. ES325_SIGNAL_RMS_PORTC_DOUT_LEFT,
  272. ES325_SIGNAL_RMS_PORTC_DOUT_RIGHT,
  273. ES325_SIGNAL_RMS_PORTD_DIN_LEFT,
  274. ES325_SIGNAL_RMS_PORTD_DIN_RIGHT,
  275. ES325_SIGNAL_RMS_PORTD_DOUT_LEFT,
  276. ES325_SIGNAL_RMS_PORTD_DOUT_RIGHT,
  277. ES325_SIGNAL_PEAK_PORTA_DIN_LEFT,
  278. ES325_SIGNAL_PEAK_PORTA_DIN_RIGHT,
  279. ES325_SIGNAL_PEAK_PORTA_DOUT_LEFT,
  280. ES325_SIGNAL_PEAK_PORTA_DOUT_RIGHT,
  281. ES325_SIGNAL_PEAK_PORTB_DIN_LEFT,
  282. ES325_SIGNAL_PEAK_PORTB_DIN_RIGHT,
  283. ES325_SIGNAL_PEAK_PORTB_DOUT_LEFT,
  284. ES325_SIGNAL_PEAK_PORTB_DOUT_RIGHT,
  285. ES325_SIGNAL_PEAK_PORTC_DIN_LEFT,
  286. ES325_SIGNAL_PEAK_PORTC_DIN_RIGHT,
  287. ES325_SIGNAL_PEAK_PORTC_DOUT_LEFT,
  288. ES325_SIGNAL_PEAK_PORTC_DOUT_RIGHT,
  289. ES325_SIGNAL_PEAK_PORTD_DIN_LEFT,
  290. ES325_SIGNAL_PEAK_PORTD_DIN_RIGHT,
  291. ES325_SIGNAL_PEAK_PORTD_DOUT_LEFT,
  292. ES325_SIGNAL_PEAK_PORTD_DOUT_RIGHT,
  293. ES325_DIGITAL_GAIN_PRIMARY,
  294. ES325_DIGITAL_GAIN_SECONDARY,
  295. ES325_DIGITAL_GAIN_TERTIARY,
  296. ES325_DIGITAL_GAIN_QUAD,
  297. ES325_DIGITAL_GAIN_FEIN,
  298. ES325_DIGITAL_GAIN_AUDIN1,
  299. ES325_DIGITAL_GAIN_AUDIN2,
  300. ES325_DIGITAL_GAIN_AUDIN3,
  301. ES325_DIGITAL_GAIN_AUDIN4,
  302. ES325_DIGITAL_GAIN_UITONE1,
  303. ES325_DIGITAL_GAIN_UITONE2,
  304. ES325_DIGITAL_GAIN_CSOUT,
  305. ES325_DIGITAL_GAIN_FEOUT1,
  306. ES325_DIGITAL_GAIN_FEOUT2,
  307. ES325_DIGITAL_GAIN_AUDOUT1,
  308. ES325_DIGITAL_GAIN_AUDOUT2,
  309. ES325_DIGITAL_GAIN_AUDOUT3,
  310. ES325_DIGITAL_GAIN_AUDOUT4,
  311. ES325_PORTA_TIMING,
  312. ES325_PORTB_TIMING,
  313. ES325_PORTC_TIMING,
  314. ES325_PORTD_TIMING,
  315. ES325_FLUSH,
  316. ES325_FW_FIRST_CHAR,
  317. ES325_FW_NEXT_CHAR,
  318. ES325_API_ADDR_MAX,
  319. };
  320. #define ES325_SLIM_CH_RX_OFFSET 152
  321. #define ES325_SLIM_CH_TX_OFFSET 156
  322. /* #define ES325_SLIM_RX_PORTS 10 */
  323. #define ES325_SLIM_RX_PORTS 6
  324. #define ES325_SLIM_TX_PORTS 6
  325. #define ES325_NUM_CODEC_SLIM_DAIS 6
  326. #define ES325_SLIM_1_PB 1
  327. #define ES325_SLIM_1_CAP 2
  328. #define ES325_SLIM_2_PB 3
  329. #define ES325_SLIM_2_CAP 4
  330. #define ES325_SLIM_3_PB 5
  331. #define ES325_SLIM_3_CAP 6
  332. #define ES325_NUM_CODEC_I2S_DAIS 4
  333. #define ES325_I2S_PORTA 7
  334. #define ES325_I2S_PORTB 8
  335. #define ES325_I2S_PORTC 9
  336. #define ES325_I2S_PORTD 10
  337. #define ES325_NUM_CODEC_DAIS (ES325_NUM_CODEC_SLIM_DAIS + ES325_NUM_CODEC_I2S_DAIS)
  338. #define ES325_SLIM_INTF 0
  339. #define ES325_I2C_INTF 1
  340. struct es325_slim_dai_data {
  341. unsigned int rate;
  342. unsigned int *ch_num;
  343. unsigned int ch_act;
  344. unsigned int ch_tot;
  345. };
  346. struct es325_slim_ch {
  347. u32 sph;
  348. u32 ch_num;
  349. u16 ch_h;
  350. u16 grph;
  351. };
  352. struct es325_priv {
  353. struct device *dev;
  354. struct snd_soc_codec *codec;
  355. struct firmware *fw;
  356. unsigned int intf;
  357. struct esxxx_platform_data *pdata;
  358. int (*dev_read)(struct es325_priv *es325, u8 *buf, int len);
  359. int (*dev_write)(struct es325_priv *es325, const u8 *buf, int len);
  360. struct i2c_client *i2c_client;
  361. struct slim_device *intf_client;
  362. struct slim_device *gen0_client;
  363. struct mutex api_mutex;
  364. struct es325_slim_dai_data dai[ES325_NUM_CODEC_SLIM_DAIS];
  365. struct es325_slim_ch slim_rx[ES325_SLIM_RX_PORTS];
  366. struct es325_slim_ch slim_tx[ES325_SLIM_TX_PORTS];
  367. struct mutex pm_mutex;
  368. int clock_enabled;
  369. int firmware_downloaded;
  370. int pm_state;
  371. struct delayed_work sleep_work;
  372. long internal_route_num;
  373. unsigned int rx1_route_enable;
  374. unsigned int tx1_route_enable;
  375. unsigned int rx2_route_enable;
  376. unsigned int ap_tx1_ch_cnt;
  377. };
  378. extern struct es325_priv es325_priv;
  379. extern struct snd_soc_codec_driver soc_codec_dev_es325;
  380. extern struct snd_soc_dai_driver es325_dai[];
  381. extern int es325_core_probe(struct device *dev);
  382. extern int es325_bootup(struct es325_priv *es325);
  383. extern int fw_download(void *arg);
  384. #endif /* _ES325_H */