ak4113.h 11 KB

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