cs8427.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * Routines for control of the CS8427 via i2c bus
  3. * IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic
  4. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <sound/driver.h>
  23. #include <linux/slab.h>
  24. #include <linux/delay.h>
  25. #include <linux/init.h>
  26. #include <sound/core.h>
  27. #include <sound/control.h>
  28. #include <sound/pcm.h>
  29. #include <sound/cs8427.h>
  30. #include <sound/asoundef.h>
  31. static void snd_cs8427_reset(snd_i2c_device_t *cs8427);
  32. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  33. MODULE_DESCRIPTION("IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic");
  34. MODULE_LICENSE("GPL");
  35. #define CS8427_ADDR (0x20>>1) /* fixed address */
  36. typedef struct {
  37. snd_pcm_substream_t *substream;
  38. char hw_status[24]; /* hardware status */
  39. char def_status[24]; /* default status */
  40. char pcm_status[24]; /* PCM private status */
  41. char hw_udata[32];
  42. snd_kcontrol_t *pcm_ctl;
  43. } cs8427_stream_t;
  44. typedef struct {
  45. unsigned char regmap[0x14]; /* map of first 1 + 13 registers */
  46. unsigned int rate;
  47. unsigned int reset_timeout;
  48. cs8427_stream_t playback;
  49. cs8427_stream_t capture;
  50. } cs8427_t;
  51. static unsigned char swapbits(unsigned char val)
  52. {
  53. int bit;
  54. unsigned char res = 0;
  55. for (bit = 0; bit < 8; bit++) {
  56. res <<= 1;
  57. res |= val & 1;
  58. val >>= 1;
  59. }
  60. return res;
  61. }
  62. int snd_cs8427_reg_write(snd_i2c_device_t *device, unsigned char reg, unsigned char val)
  63. {
  64. int err;
  65. unsigned char buf[2];
  66. buf[0] = reg & 0x7f;
  67. buf[1] = val;
  68. if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) {
  69. snd_printk(KERN_ERR "unable to send bytes 0x%02x:0x%02x to CS8427 (%i)\n", buf[0], buf[1], err);
  70. return err < 0 ? err : -EIO;
  71. }
  72. return 0;
  73. }
  74. static int snd_cs8427_reg_read(snd_i2c_device_t *device, unsigned char reg)
  75. {
  76. int err;
  77. unsigned char buf;
  78. if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
  79. snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
  80. return err < 0 ? err : -EIO;
  81. }
  82. if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) {
  83. snd_printk(KERN_ERR "unable to read register 0x%x byte from CS8427\n", reg);
  84. return err < 0 ? err : -EIO;
  85. }
  86. return buf;
  87. }
  88. static int snd_cs8427_select_corudata(snd_i2c_device_t *device, int udata)
  89. {
  90. cs8427_t *chip = device->private_data;
  91. int err;
  92. udata = udata ? CS8427_BSEL : 0;
  93. if (udata != (chip->regmap[CS8427_REG_CSDATABUF] & udata)) {
  94. chip->regmap[CS8427_REG_CSDATABUF] &= ~CS8427_BSEL;
  95. chip->regmap[CS8427_REG_CSDATABUF] |= udata;
  96. err = snd_cs8427_reg_write(device, CS8427_REG_CSDATABUF, chip->regmap[CS8427_REG_CSDATABUF]);
  97. if (err < 0)
  98. return err;
  99. }
  100. return 0;
  101. }
  102. static int snd_cs8427_send_corudata(snd_i2c_device_t *device,
  103. int udata,
  104. unsigned char *ndata,
  105. int count)
  106. {
  107. cs8427_t *chip = device->private_data;
  108. char *hw_data = udata ? chip->playback.hw_udata : chip->playback.hw_status;
  109. char data[32];
  110. int err, idx;
  111. if (!memcmp(hw_data, ndata, count))
  112. return 0;
  113. if ((err = snd_cs8427_select_corudata(device, udata)) < 0)
  114. return err;
  115. memcpy(hw_data, ndata, count);
  116. if (udata) {
  117. memset(data, 0, sizeof(data));
  118. if (memcmp(hw_data, data, count) == 0) {
  119. chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK;
  120. chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | CS8427_EFTUI;
  121. if ((err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF, chip->regmap[CS8427_REG_UDATABUF])) < 0)
  122. return err;
  123. return 0;
  124. }
  125. }
  126. data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF;
  127. for (idx = 0; idx < count; idx++)
  128. data[idx + 1] = swapbits(ndata[idx]);
  129. if (snd_i2c_sendbytes(device, data, count + 1) != count + 1)
  130. return -EIO;
  131. return 1;
  132. }
  133. static void snd_cs8427_free(snd_i2c_device_t *device)
  134. {
  135. kfree(device->private_data);
  136. }
  137. int snd_cs8427_create(snd_i2c_bus_t *bus,
  138. unsigned char addr,
  139. unsigned int reset_timeout,
  140. snd_i2c_device_t **r_cs8427)
  141. {
  142. static unsigned char initvals1[] = {
  143. CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC,
  144. /* CS8427_REG_CONTROL1: RMCK to OMCK, valid PCM audio, disable mutes, TCBL=output */
  145. CS8427_SWCLK | CS8427_TCBLDIR,
  146. /* CS8427_REG_CONTROL2: hold last valid audio sample, RMCK=256*Fs, normal stereo operation */
  147. 0x00,
  148. /* CS8427_REG_DATAFLOW: output drivers normal operation, Tx<=serial, Rx=>serial */
  149. CS8427_TXDSERIAL | CS8427_SPDAES3RECEIVER,
  150. /* CS8427_REG_CLOCKSOURCE: Run off, CMCK=256*Fs, output time base = OMCK, input time base =
  151. recovered input clock, recovered input clock source is ILRCK changed to AES3INPUT (workaround, see snd_cs8427_reset) */
  152. CS8427_RXDILRCK,
  153. /* CS8427_REG_SERIALINPUT: Serial audio input port data format = I2S, 24-bit, 64*Fsi */
  154. CS8427_SIDEL | CS8427_SILRPOL,
  155. /* CS8427_REG_SERIALOUTPUT: Serial audio output port data format = I2S, 24-bit, 64*Fsi */
  156. CS8427_SODEL | CS8427_SOLRPOL,
  157. };
  158. static unsigned char initvals2[] = {
  159. CS8427_REG_RECVERRMASK | CS8427_REG_AUTOINC,
  160. /* CS8427_REG_RECVERRMASK: unmask the input PLL clock, V, confidence, biphase, parity status bits */
  161. /* CS8427_UNLOCK | CS8427_V | CS8427_CONF | CS8427_BIP | CS8427_PAR, */
  162. 0xff, /* set everything */
  163. /* CS8427_REG_CSDATABUF:
  164. Registers 32-55 window to CS buffer
  165. Inhibit D->E transfers from overwriting first 5 bytes of CS data.
  166. Inhibit D->E transfers (all) of CS data.
  167. Allow E->F transfer of CS data.
  168. One byte mode; both A/B channels get same written CB data.
  169. A channel info is output to chip's EMPH* pin. */
  170. CS8427_CBMR | CS8427_DETCI,
  171. /* CS8427_REG_UDATABUF:
  172. Use internal buffer to transmit User (U) data.
  173. Chip's U pin is an output.
  174. Transmit all O's for user data.
  175. Inhibit D->E transfers.
  176. Inhibit E->F transfers. */
  177. CS8427_UD | CS8427_EFTUI | CS8427_DETUI,
  178. };
  179. int err;
  180. cs8427_t *chip;
  181. snd_i2c_device_t *device;
  182. unsigned char buf[24];
  183. if ((err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7), &device)) < 0)
  184. return err;
  185. chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL);
  186. if (chip == NULL) {
  187. snd_i2c_device_free(device);
  188. return -ENOMEM;
  189. }
  190. device->private_free = snd_cs8427_free;
  191. snd_i2c_lock(bus);
  192. if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != CS8427_VER8427A) {
  193. snd_i2c_unlock(bus);
  194. snd_printk(KERN_ERR "unable to find CS8427 signature (expected 0x%x, read 0x%x), initialization is not completed\n", CS8427_VER8427A, err);
  195. return -EFAULT;
  196. }
  197. /* turn off run bit while making changes to configuration */
  198. if ((err = snd_cs8427_reg_write(device, CS8427_REG_CLOCKSOURCE, 0x00)) < 0)
  199. goto __fail;
  200. /* send initial values */
  201. memcpy(chip->regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6);
  202. if ((err = snd_i2c_sendbytes(device, initvals1, 7)) != 7) {
  203. err = err < 0 ? err : -EIO;
  204. goto __fail;
  205. }
  206. /* Turn off CS8427 interrupt stuff that is not used in hardware */
  207. memset(buf, 0, 7);
  208. /* from address 9 to 15 */
  209. buf[0] = 9; /* register */
  210. if ((err = snd_i2c_sendbytes(device, buf, 7)) != 7)
  211. goto __fail;
  212. /* send transfer initialization sequence */
  213. memcpy(chip->regmap + (initvals2[0] & 0x7f), initvals2 + 1, 3);
  214. if ((err = snd_i2c_sendbytes(device, initvals2, 4)) != 4) {
  215. err = err < 0 ? err : -EIO;
  216. goto __fail;
  217. }
  218. /* write default channel status bytes */
  219. buf[0] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 0));
  220. buf[1] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 8));
  221. buf[2] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 16));
  222. buf[3] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 24));
  223. memset(buf + 4, 0, 24 - 4);
  224. if (snd_cs8427_send_corudata(device, 0, buf, 24) < 0)
  225. goto __fail;
  226. memcpy(chip->playback.def_status, buf, 24);
  227. memcpy(chip->playback.pcm_status, buf, 24);
  228. snd_i2c_unlock(bus);
  229. /* turn on run bit and rock'n'roll */
  230. if (reset_timeout < 1)
  231. reset_timeout = 1;
  232. chip->reset_timeout = reset_timeout;
  233. snd_cs8427_reset(device);
  234. #if 0 // it's nice for read tests
  235. {
  236. char buf[128];
  237. int xx;
  238. buf[0] = 0x81;
  239. snd_i2c_sendbytes(device, buf, 1);
  240. snd_i2c_readbytes(device, buf, 127);
  241. for (xx = 0; xx < 127; xx++)
  242. printk(KERN_DEBUG "reg[0x%x] = 0x%x\n", xx+1, buf[xx]);
  243. }
  244. #endif
  245. if (r_cs8427)
  246. *r_cs8427 = device;
  247. return 0;
  248. __fail:
  249. snd_i2c_unlock(bus);
  250. snd_i2c_device_free(device);
  251. return err < 0 ? err : -EIO;
  252. }
  253. /*
  254. * Reset the chip using run bit, also lock PLL using ILRCK and
  255. * put back AES3INPUT. This workaround is described in latest
  256. * CS8427 datasheet, otherwise TXDSERIAL will not work.
  257. */
  258. static void snd_cs8427_reset(snd_i2c_device_t *cs8427)
  259. {
  260. cs8427_t *chip;
  261. unsigned long end_time;
  262. int data;
  263. snd_assert(cs8427, return);
  264. chip = cs8427->private_data;
  265. snd_i2c_lock(cs8427->bus);
  266. chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK);
  267. snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]);
  268. udelay(200);
  269. chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RUN | CS8427_RXDILRCK;
  270. snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]);
  271. udelay(200);
  272. snd_i2c_unlock(cs8427->bus);
  273. end_time = jiffies + chip->reset_timeout;
  274. while (time_after_eq(end_time, jiffies)) {
  275. snd_i2c_lock(cs8427->bus);
  276. data = snd_cs8427_reg_read(cs8427, CS8427_REG_RECVERRORS);
  277. snd_i2c_unlock(cs8427->bus);
  278. if (!(data & CS8427_UNLOCK))
  279. break;
  280. schedule_timeout_uninterruptible(1);
  281. }
  282. snd_i2c_lock(cs8427->bus);
  283. chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK;
  284. chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RXDAES3INPUT;
  285. snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]);
  286. snd_i2c_unlock(cs8427->bus);
  287. }
  288. static int snd_cs8427_in_status_info(snd_kcontrol_t *kcontrol,
  289. snd_ctl_elem_info_t *uinfo)
  290. {
  291. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  292. uinfo->count = 1;
  293. uinfo->value.integer.min = 0;
  294. uinfo->value.integer.max = 255;
  295. return 0;
  296. }
  297. static int snd_cs8427_in_status_get(snd_kcontrol_t *kcontrol,
  298. snd_ctl_elem_value_t *ucontrol)
  299. {
  300. snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol);
  301. int data;
  302. snd_i2c_lock(device->bus);
  303. data = snd_cs8427_reg_read(device, kcontrol->private_value);
  304. snd_i2c_unlock(device->bus);
  305. if (data < 0)
  306. return data;
  307. ucontrol->value.integer.value[0] = data;
  308. return 0;
  309. }
  310. static int snd_cs8427_qsubcode_info(snd_kcontrol_t *kcontrol,
  311. snd_ctl_elem_info_t *uinfo)
  312. {
  313. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  314. uinfo->count = 10;
  315. return 0;
  316. }
  317. static int snd_cs8427_qsubcode_get(snd_kcontrol_t *kcontrol,
  318. snd_ctl_elem_value_t *ucontrol)
  319. {
  320. snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol);
  321. unsigned char reg = CS8427_REG_QSUBCODE;
  322. int err;
  323. snd_i2c_lock(device->bus);
  324. if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
  325. snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
  326. snd_i2c_unlock(device->bus);
  327. return err < 0 ? err : -EIO;
  328. }
  329. if ((err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10)) != 10) {
  330. snd_printk(KERN_ERR "unable to read Q-subcode bytes from CS8427\n");
  331. snd_i2c_unlock(device->bus);
  332. return err < 0 ? err : -EIO;
  333. }
  334. snd_i2c_unlock(device->bus);
  335. return 0;
  336. }
  337. static int snd_cs8427_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  338. {
  339. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  340. uinfo->count = 1;
  341. return 0;
  342. }
  343. static int snd_cs8427_spdif_get(snd_kcontrol_t * kcontrol,
  344. snd_ctl_elem_value_t * ucontrol)
  345. {
  346. snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol);
  347. cs8427_t *chip = device->private_data;
  348. snd_i2c_lock(device->bus);
  349. memcpy(ucontrol->value.iec958.status, chip->playback.def_status, 24);
  350. snd_i2c_unlock(device->bus);
  351. return 0;
  352. }
  353. static int snd_cs8427_spdif_put(snd_kcontrol_t * kcontrol,
  354. snd_ctl_elem_value_t * ucontrol)
  355. {
  356. snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol);
  357. cs8427_t *chip = device->private_data;
  358. unsigned char *status = kcontrol->private_value ? chip->playback.pcm_status : chip->playback.def_status;
  359. snd_pcm_runtime_t *runtime = chip->playback.substream ? chip->playback.substream->runtime : NULL;
  360. int err, change;
  361. snd_i2c_lock(device->bus);
  362. change = memcmp(ucontrol->value.iec958.status, status, 24) != 0;
  363. memcpy(status, ucontrol->value.iec958.status, 24);
  364. if (change && (kcontrol->private_value ? runtime != NULL : runtime == NULL)) {
  365. err = snd_cs8427_send_corudata(device, 0, status, 24);
  366. if (err < 0)
  367. change = err;
  368. }
  369. snd_i2c_unlock(device->bus);
  370. return change;
  371. }
  372. static int snd_cs8427_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  373. {
  374. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  375. uinfo->count = 1;
  376. return 0;
  377. }
  378. static int snd_cs8427_spdif_mask_get(snd_kcontrol_t * kcontrol,
  379. snd_ctl_elem_value_t * ucontrol)
  380. {
  381. memset(ucontrol->value.iec958.status, 0xff, 24);
  382. return 0;
  383. }
  384. static snd_kcontrol_new_t snd_cs8427_iec958_controls[] = {
  385. {
  386. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  387. .info = snd_cs8427_in_status_info,
  388. .name = "IEC958 CS8427 Input Status",
  389. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  390. .get = snd_cs8427_in_status_get,
  391. .private_value = 15,
  392. },
  393. {
  394. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  395. .info = snd_cs8427_in_status_info,
  396. .name = "IEC958 CS8427 Error Status",
  397. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  398. .get = snd_cs8427_in_status_get,
  399. .private_value = 16,
  400. },
  401. {
  402. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  403. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  404. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  405. .info = snd_cs8427_spdif_mask_info,
  406. .get = snd_cs8427_spdif_mask_get,
  407. },
  408. {
  409. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  410. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  411. .info = snd_cs8427_spdif_info,
  412. .get = snd_cs8427_spdif_get,
  413. .put = snd_cs8427_spdif_put,
  414. .private_value = 0
  415. },
  416. {
  417. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  418. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  419. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  420. .info = snd_cs8427_spdif_info,
  421. .get = snd_cs8427_spdif_get,
  422. .put = snd_cs8427_spdif_put,
  423. .private_value = 1
  424. },
  425. {
  426. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  427. .info = snd_cs8427_qsubcode_info,
  428. .name = "IEC958 Q-subcode Capture Default",
  429. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  430. .get = snd_cs8427_qsubcode_get
  431. }};
  432. int snd_cs8427_iec958_build(snd_i2c_device_t *cs8427,
  433. snd_pcm_substream_t *play_substream,
  434. snd_pcm_substream_t *cap_substream)
  435. {
  436. cs8427_t *chip = cs8427->private_data;
  437. snd_kcontrol_t *kctl;
  438. unsigned int idx;
  439. int err;
  440. snd_assert(play_substream && cap_substream, return -EINVAL);
  441. for (idx = 0; idx < ARRAY_SIZE(snd_cs8427_iec958_controls); idx++) {
  442. kctl = snd_ctl_new1(&snd_cs8427_iec958_controls[idx], cs8427);
  443. if (kctl == NULL)
  444. return -ENOMEM;
  445. kctl->id.device = play_substream->pcm->device;
  446. kctl->id.subdevice = play_substream->number;
  447. err = snd_ctl_add(cs8427->bus->card, kctl);
  448. if (err < 0)
  449. return err;
  450. if (!strcmp(kctl->id.name, SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM)))
  451. chip->playback.pcm_ctl = kctl;
  452. }
  453. chip->playback.substream = play_substream;
  454. chip->capture.substream = cap_substream;
  455. snd_assert(chip->playback.pcm_ctl, return -EIO);
  456. return 0;
  457. }
  458. int snd_cs8427_iec958_active(snd_i2c_device_t *cs8427, int active)
  459. {
  460. cs8427_t *chip;
  461. snd_assert(cs8427, return -ENXIO);
  462. chip = cs8427->private_data;
  463. if (active)
  464. memcpy(chip->playback.pcm_status, chip->playback.def_status, 24);
  465. chip->playback.pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  466. snd_ctl_notify(cs8427->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
  467. SNDRV_CTL_EVENT_MASK_INFO, &chip->playback.pcm_ctl->id);
  468. return 0;
  469. }
  470. int snd_cs8427_iec958_pcm(snd_i2c_device_t *cs8427, unsigned int rate)
  471. {
  472. cs8427_t *chip;
  473. char *status;
  474. int err, reset;
  475. snd_assert(cs8427, return -ENXIO);
  476. chip = cs8427->private_data;
  477. status = chip->playback.pcm_status;
  478. snd_i2c_lock(cs8427->bus);
  479. if (status[0] & IEC958_AES0_PROFESSIONAL) {
  480. status[0] &= ~IEC958_AES0_PRO_FS;
  481. switch (rate) {
  482. case 32000: status[0] |= IEC958_AES0_PRO_FS_32000; break;
  483. case 44100: status[0] |= IEC958_AES0_PRO_FS_44100; break;
  484. case 48000: status[0] |= IEC958_AES0_PRO_FS_48000; break;
  485. default: status[0] |= IEC958_AES0_PRO_FS_NOTID; break;
  486. }
  487. } else {
  488. status[3] &= ~IEC958_AES3_CON_FS;
  489. switch (rate) {
  490. case 32000: status[3] |= IEC958_AES3_CON_FS_32000; break;
  491. case 44100: status[3] |= IEC958_AES3_CON_FS_44100; break;
  492. case 48000: status[3] |= IEC958_AES3_CON_FS_48000; break;
  493. }
  494. }
  495. err = snd_cs8427_send_corudata(cs8427, 0, status, 24);
  496. if (err > 0)
  497. snd_ctl_notify(cs8427->bus->card,
  498. SNDRV_CTL_EVENT_MASK_VALUE,
  499. &chip->playback.pcm_ctl->id);
  500. reset = chip->rate != rate;
  501. chip->rate = rate;
  502. snd_i2c_unlock(cs8427->bus);
  503. if (reset)
  504. snd_cs8427_reset(cs8427);
  505. return err < 0 ? err : 0;
  506. }
  507. static int __init alsa_cs8427_module_init(void)
  508. {
  509. return 0;
  510. }
  511. static void __exit alsa_cs8427_module_exit(void)
  512. {
  513. }
  514. module_init(alsa_cs8427_module_init)
  515. module_exit(alsa_cs8427_module_exit)
  516. EXPORT_SYMBOL(snd_cs8427_create);
  517. EXPORT_SYMBOL(snd_cs8427_reset);
  518. EXPORT_SYMBOL(snd_cs8427_reg_write);
  519. EXPORT_SYMBOL(snd_cs8427_iec958_build);
  520. EXPORT_SYMBOL(snd_cs8427_iec958_active);
  521. EXPORT_SYMBOL(snd_cs8427_iec958_pcm);