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