ak4113.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_AK4113_H
  3. #define __SOUND_AK4113_H
  4. /*
  5. * Routines for Asahi Kasei AK4113
  6. * Copyright (c) by Jaroslav Kysela <[email protected]>,
  7. * Copyright (c) by Pavel Hofman <[email protected]>,
  8. */
  9. /* AK4113 registers */
  10. /* power down */
  11. #define AK4113_REG_PWRDN 0x00
  12. /* format control */
  13. #define AK4113_REG_FORMAT 0x01
  14. /* input/output control */
  15. #define AK4113_REG_IO0 0x02
  16. /* input/output control */
  17. #define AK4113_REG_IO1 0x03
  18. /* interrupt0 mask */
  19. #define AK4113_REG_INT0_MASK 0x04
  20. /* interrupt1 mask */
  21. #define AK4113_REG_INT1_MASK 0x05
  22. /* DAT mask & DTS select */
  23. #define AK4113_REG_DATDTS 0x06
  24. /* receiver status 0 */
  25. #define AK4113_REG_RCS0 0x07
  26. /* receiver status 1 */
  27. #define AK4113_REG_RCS1 0x08
  28. /* receiver status 2 */
  29. #define AK4113_REG_RCS2 0x09
  30. /* RX channel status byte 0 */
  31. #define AK4113_REG_RXCSB0 0x0a
  32. /* RX channel status byte 1 */
  33. #define AK4113_REG_RXCSB1 0x0b
  34. /* RX channel status byte 2 */
  35. #define AK4113_REG_RXCSB2 0x0c
  36. /* RX channel status byte 3 */
  37. #define AK4113_REG_RXCSB3 0x0d
  38. /* RX channel status byte 4 */
  39. #define AK4113_REG_RXCSB4 0x0e
  40. /* burst preamble Pc byte 0 */
  41. #define AK4113_REG_Pc0 0x0f
  42. /* burst preamble Pc byte 1 */
  43. #define AK4113_REG_Pc1 0x10
  44. /* burst preamble Pd byte 0 */
  45. #define AK4113_REG_Pd0 0x11
  46. /* burst preamble Pd byte 1 */
  47. #define AK4113_REG_Pd1 0x12
  48. /* Q-subcode address + control */
  49. #define AK4113_REG_QSUB_ADDR 0x13
  50. /* Q-subcode track */
  51. #define AK4113_REG_QSUB_TRACK 0x14
  52. /* Q-subcode index */
  53. #define AK4113_REG_QSUB_INDEX 0x15
  54. /* Q-subcode minute */
  55. #define AK4113_REG_QSUB_MINUTE 0x16
  56. /* Q-subcode second */
  57. #define AK4113_REG_QSUB_SECOND 0x17
  58. /* Q-subcode frame */
  59. #define AK4113_REG_QSUB_FRAME 0x18
  60. /* Q-subcode zero */
  61. #define AK4113_REG_QSUB_ZERO 0x19
  62. /* Q-subcode absolute minute */
  63. #define AK4113_REG_QSUB_ABSMIN 0x1a
  64. /* Q-subcode absolute second */
  65. #define AK4113_REG_QSUB_ABSSEC 0x1b
  66. /* Q-subcode absolute frame */
  67. #define AK4113_REG_QSUB_ABSFRM 0x1c
  68. /* sizes */
  69. #define AK4113_REG_RXCSB_SIZE ((AK4113_REG_RXCSB4-AK4113_REG_RXCSB0)+1)
  70. #define AK4113_REG_QSUB_SIZE ((AK4113_REG_QSUB_ABSFRM-AK4113_REG_QSUB_ADDR)\
  71. +1)
  72. #define AK4113_WRITABLE_REGS (AK4113_REG_DATDTS + 1)
  73. /* AK4113_REG_PWRDN bits */
  74. /* Channel Status Select */
  75. #define AK4113_CS12 (1<<7)
  76. /* Block Start & C/U Output Mode */
  77. #define AK4113_BCU (1<<6)
  78. /* Master Clock Operation Select */
  79. #define AK4113_CM1 (1<<5)
  80. /* Master Clock Operation Select */
  81. #define AK4113_CM0 (1<<4)
  82. /* Master Clock Frequency Select */
  83. #define AK4113_OCKS1 (1<<3)
  84. /* Master Clock Frequency Select */
  85. #define AK4113_OCKS0 (1<<2)
  86. /* 0 = power down, 1 = normal operation */
  87. #define AK4113_PWN (1<<1)
  88. /* 0 = reset & initialize (except thisregister), 1 = normal operation */
  89. #define AK4113_RST (1<<0)
  90. /* AK4113_REQ_FORMAT bits */
  91. /* V/TX Output select: 0 = Validity Flag Output, 1 = TX */
  92. #define AK4113_VTX (1<<7)
  93. /* Audio Data Control */
  94. #define AK4113_DIF2 (1<<6)
  95. /* Audio Data Control */
  96. #define AK4113_DIF1 (1<<5)
  97. /* Audio Data Control */
  98. #define AK4113_DIF0 (1<<4)
  99. /* Deemphasis Autodetect Enable (1 = enable) */
  100. #define AK4113_DEAU (1<<3)
  101. /* 32kHz-48kHz Deemphasis Control */
  102. #define AK4113_DEM1 (1<<2)
  103. /* 32kHz-48kHz Deemphasis Control */
  104. #define AK4113_DEM0 (1<<1)
  105. #define AK4113_DEM_OFF (AK4113_DEM0)
  106. #define AK4113_DEM_44KHZ (0)
  107. #define AK4113_DEM_48KHZ (AK4113_DEM1)
  108. #define AK4113_DEM_32KHZ (AK4113_DEM0|AK4113_DEM1)
  109. /* STDO: 16-bit, right justified */
  110. #define AK4113_DIF_16R (0)
  111. /* STDO: 18-bit, right justified */
  112. #define AK4113_DIF_18R (AK4113_DIF0)
  113. /* STDO: 20-bit, right justified */
  114. #define AK4113_DIF_20R (AK4113_DIF1)
  115. /* STDO: 24-bit, right justified */
  116. #define AK4113_DIF_24R (AK4113_DIF1|AK4113_DIF0)
  117. /* STDO: 24-bit, left justified */
  118. #define AK4113_DIF_24L (AK4113_DIF2)
  119. /* STDO: I2S */
  120. #define AK4113_DIF_24I2S (AK4113_DIF2|AK4113_DIF0)
  121. /* STDO: 24-bit, left justified; LRCLK, BICK = Input */
  122. #define AK4113_DIF_I24L (AK4113_DIF2|AK4113_DIF1)
  123. /* STDO: I2S; LRCLK, BICK = Input */
  124. #define AK4113_DIF_I24I2S (AK4113_DIF2|AK4113_DIF1|AK4113_DIF0)
  125. /* AK4113_REG_IO0 */
  126. /* XTL1=0,XTL0=0 -> 11.2896Mhz; XTL1=0,XTL0=1 -> 12.288Mhz */
  127. #define AK4113_XTL1 (1<<6)
  128. /* XTL1=1,XTL0=0 -> 24.576Mhz; XTL1=1,XTL0=1 -> use channel status */
  129. #define AK4113_XTL0 (1<<5)
  130. /* Block Start Signal Output: 0 = U-bit, 1 = C-bit (req. BCU = 1) */
  131. #define AK4113_UCE (1<<4)
  132. /* TX Output Enable (1 = enable) */
  133. #define AK4113_TXE (1<<3)
  134. /* Output Through Data Selector for TX pin */
  135. #define AK4113_OPS2 (1<<2)
  136. /* Output Through Data Selector for TX pin */
  137. #define AK4113_OPS1 (1<<1)
  138. /* Output Through Data Selector for TX pin */
  139. #define AK4113_OPS0 (1<<0)
  140. /* 11.2896 MHz ref. Xtal freq. */
  141. #define AK4113_XTL_11_2896M (0)
  142. /* 12.288 MHz ref. Xtal freq. */
  143. #define AK4113_XTL_12_288M (AK4113_XTL0)
  144. /* 24.576 MHz ref. Xtal freq. */
  145. #define AK4113_XTL_24_576M (AK4113_XTL1)
  146. /* AK4113_REG_IO1 */
  147. /* Interrupt 0 pin Hold */
  148. #define AK4113_EFH1 (1<<7)
  149. /* Interrupt 0 pin Hold */
  150. #define AK4113_EFH0 (1<<6)
  151. #define AK4113_EFH_512LRCLK (0)
  152. #define AK4113_EFH_1024LRCLK (AK4113_EFH0)
  153. #define AK4113_EFH_2048LRCLK (AK4113_EFH1)
  154. #define AK4113_EFH_4096LRCLK (AK4113_EFH1|AK4113_EFH0)
  155. /* PLL Lock Time: 0 = 384/fs, 1 = 1/fs */
  156. #define AK4113_FAST (1<<5)
  157. /* MCKO2 Output Select: 0 = CMx/OCKSx, 1 = Xtal */
  158. #define AK4113_XMCK (1<<4)
  159. /* MCKO2 Output Freq. Select: 0 = x1, 1 = x0.5 (req. XMCK = 1) */
  160. #define AK4113_DIV (1<<3)
  161. /* Input Recovery Data Select */
  162. #define AK4113_IPS2 (1<<2)
  163. /* Input Recovery Data Select */
  164. #define AK4113_IPS1 (1<<1)
  165. /* Input Recovery Data Select */
  166. #define AK4113_IPS0 (1<<0)
  167. #define AK4113_IPS(x) ((x)&7)
  168. /* AK4113_REG_INT0_MASK && AK4113_REG_INT1_MASK*/
  169. /* mask enable for QINT bit */
  170. #define AK4113_MQI (1<<7)
  171. /* mask enable for AUTO bit */
  172. #define AK4113_MAUT (1<<6)
  173. /* mask enable for CINT bit */
  174. #define AK4113_MCIT (1<<5)
  175. /* mask enable for UNLOCK bit */
  176. #define AK4113_MULK (1<<4)
  177. /* mask enable for V bit */
  178. #define AK4113_V (1<<3)
  179. /* mask enable for STC bit */
  180. #define AK4113_STC (1<<2)
  181. /* mask enable for AUDN bit */
  182. #define AK4113_MAN (1<<1)
  183. /* mask enable for PAR bit */
  184. #define AK4113_MPR (1<<0)
  185. /* AK4113_REG_DATDTS */
  186. /* DAT Start ID Counter */
  187. #define AK4113_DCNT (1<<4)
  188. /* DTS-CD 16-bit Sync Word Detect */
  189. #define AK4113_DTS16 (1<<3)
  190. /* DTS-CD 14-bit Sync Word Detect */
  191. #define AK4113_DTS14 (1<<2)
  192. /* mask enable for DAT bit (if 1, no INT1 effect */
  193. #define AK4113_MDAT1 (1<<1)
  194. /* mask enable for DAT bit (if 1, no INT0 effect */
  195. #define AK4113_MDAT0 (1<<0)
  196. /* AK4113_REG_RCS0 */
  197. /* Q-subcode buffer interrupt, 0 = no change, 1 = changed */
  198. #define AK4113_QINT (1<<7)
  199. /* Non-PCM or DTS stream auto detection, 0 = no detect, 1 = detect */
  200. #define AK4113_AUTO (1<<6)
  201. /* channel status buffer interrupt, 0 = no change, 1 = change */
  202. #define AK4113_CINT (1<<5)
  203. /* PLL lock status, 0 = lock, 1 = unlock */
  204. #define AK4113_UNLCK (1<<4)
  205. /* Validity bit, 0 = valid, 1 = invalid */
  206. #define AK4113_V (1<<3)
  207. /* sampling frequency or Pre-emphasis change, 0 = no detect, 1 = detect */
  208. #define AK4113_STC (1<<2)
  209. /* audio bit output, 0 = audio, 1 = non-audio */
  210. #define AK4113_AUDION (1<<1)
  211. /* parity error or biphase error status, 0 = no error, 1 = error */
  212. #define AK4113_PAR (1<<0)
  213. /* AK4113_REG_RCS1 */
  214. /* sampling frequency detection */
  215. #define AK4113_FS3 (1<<7)
  216. #define AK4113_FS2 (1<<6)
  217. #define AK4113_FS1 (1<<5)
  218. #define AK4113_FS0 (1<<4)
  219. /* Pre-emphasis detect, 0 = OFF, 1 = ON */
  220. #define AK4113_PEM (1<<3)
  221. /* DAT Start ID Detect, 0 = no detect, 1 = detect */
  222. #define AK4113_DAT (1<<2)
  223. /* DTS-CD bit audio stream detect, 0 = no detect, 1 = detect */
  224. #define AK4113_DTSCD (1<<1)
  225. /* Non-PCM bit stream detection, 0 = no detect, 1 = detect */
  226. #define AK4113_NPCM (1<<0)
  227. #define AK4113_FS_8000HZ (AK4113_FS3|AK4113_FS0)
  228. #define AK4113_FS_11025HZ (AK4113_FS2|AK4113_FS0)
  229. #define AK4113_FS_16000HZ (AK4113_FS2|AK4113_FS1|AK4113_FS0)
  230. #define AK4113_FS_22050HZ (AK4113_FS2)
  231. #define AK4113_FS_24000HZ (AK4113_FS2|AK4113_FS1)
  232. #define AK4113_FS_32000HZ (AK4113_FS1|AK4113_FS0)
  233. #define AK4113_FS_44100HZ (0)
  234. #define AK4113_FS_48000HZ (AK4113_FS1)
  235. #define AK4113_FS_64000HZ (AK4113_FS3|AK4113_FS1|AK4113_FS0)
  236. #define AK4113_FS_88200HZ (AK4113_FS3)
  237. #define AK4113_FS_96000HZ (AK4113_FS3|AK4113_FS1)
  238. #define AK4113_FS_176400HZ (AK4113_FS3|AK4113_FS2)
  239. #define AK4113_FS_192000HZ (AK4113_FS3|AK4113_FS2|AK4113_FS1)
  240. /* AK4113_REG_RCS2 */
  241. /* CRC for Q-subcode, 0 = no error, 1 = error */
  242. #define AK4113_QCRC (1<<1)
  243. /* CRC for channel status, 0 = no error, 1 = error */
  244. #define AK4113_CCRC (1<<0)
  245. /* flags for snd_ak4113_check_rate_and_errors() */
  246. #define AK4113_CHECK_NO_STAT (1<<0) /* no statistics */
  247. #define AK4113_CHECK_NO_RATE (1<<1) /* no rate check */
  248. #define AK4113_CONTROLS 13
  249. typedef void (ak4113_write_t)(void *private_data, unsigned char addr,
  250. unsigned char data);
  251. typedef unsigned char (ak4113_read_t)(void *private_data, unsigned char addr);
  252. enum {
  253. AK4113_PARITY_ERRORS,
  254. AK4113_V_BIT_ERRORS,
  255. AK4113_QCRC_ERRORS,
  256. AK4113_CCRC_ERRORS,
  257. AK4113_NUM_ERRORS
  258. };
  259. struct ak4113 {
  260. struct snd_card *card;
  261. ak4113_write_t *write;
  262. ak4113_read_t *read;
  263. void *private_data;
  264. atomic_t wq_processing;
  265. struct mutex reinit_mutex;
  266. spinlock_t lock;
  267. unsigned char regmap[AK4113_WRITABLE_REGS];
  268. struct snd_kcontrol *kctls[AK4113_CONTROLS];
  269. struct snd_pcm_substream *substream;
  270. unsigned long errors[AK4113_NUM_ERRORS];
  271. unsigned char rcs0;
  272. unsigned char rcs1;
  273. unsigned char rcs2;
  274. struct delayed_work work;
  275. unsigned int check_flags;
  276. void *change_callback_private;
  277. void (*change_callback)(struct ak4113 *ak4113, unsigned char c0,
  278. unsigned char c1);
  279. };
  280. int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
  281. ak4113_write_t *write,
  282. const unsigned char *pgm,
  283. void *private_data, struct ak4113 **r_ak4113);
  284. void snd_ak4113_reg_write(struct ak4113 *ak4113, unsigned char reg,
  285. unsigned char mask, unsigned char val);
  286. void snd_ak4113_reinit(struct ak4113 *ak4113);
  287. int snd_ak4113_build(struct ak4113 *ak4113,
  288. struct snd_pcm_substream *capture_substream);
  289. int snd_ak4113_external_rate(struct ak4113 *ak4113);
  290. int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags);
  291. #ifdef CONFIG_PM
  292. void snd_ak4113_suspend(struct ak4113 *chip);
  293. void snd_ak4113_resume(struct ak4113 *chip);
  294. #else
  295. static inline void snd_ak4113_suspend(struct ak4113 *chip) {}
  296. static inline void snd_ak4113_resume(struct ak4113 *chip) {}
  297. #endif
  298. #endif /* __SOUND_AK4113_H */