| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Routines for control of the AK4114 via I2C and 4-wire serial interface | 
					
						
							|  |  |  |  *  IEC958 (S/PDIF) receiver by Asahi Kasei | 
					
						
							| 
									
										
										
										
											2007-10-15 09:50:19 +02:00
										 |  |  |  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz> | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  *   it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  *   the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  *   (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *   GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  *   along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							| 
									
										
										
										
											2011-07-15 12:38:28 -04:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <sound/core.h>
 | 
					
						
							|  |  |  | #include <sound/control.h>
 | 
					
						
							|  |  |  | #include <sound/pcm.h>
 | 
					
						
							|  |  |  | #include <sound/ak4114.h>
 | 
					
						
							|  |  |  | #include <sound/asoundef.h>
 | 
					
						
							| 
									
										
										
										
											2008-02-11 14:48:06 +01:00
										 |  |  | #include <sound/info.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-15 09:50:19 +02:00
										 |  |  | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define AK4114_ADDR			0x00 /* fixed address */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-22 14:57:56 +00:00
										 |  |  | static void ak4114_stats(struct work_struct *work); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | static void ak4114_init_regs(struct ak4114 *chip); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static void reg_write(struct ak4114 *ak4114, unsigned char reg, unsigned char val) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	ak4114->write(ak4114->private_data, reg, val); | 
					
						
							|  |  |  | 	if (reg <= AK4114_REG_INT1_MASK) | 
					
						
							|  |  |  | 		ak4114->regmap[reg] = val; | 
					
						
							| 
									
										
										
										
											2007-02-05 13:07:04 +01:00
										 |  |  | 	else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4) | 
					
						
							|  |  |  | 		ak4114->txcsb[reg-AK4114_REG_TXCSB0] = val; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static inline unsigned char reg_read(struct ak4114 *ak4114, unsigned char reg) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ak4114->read(ak4114->private_data, reg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static void reg_dump(struct ak4114 *ak4114) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-20 18:26:44 +02:00
										 |  |  | 	printk(KERN_DEBUG "AK4114 REG DUMP:\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	for (i = 0; i < 0x20; i++) | 
					
						
							| 
									
										
										
										
											2013-10-29 16:37:11 +01:00
										 |  |  | 		printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < ARRAY_SIZE(ak4114->regmap) ? ak4114->regmap[i] : 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static void snd_ak4114_free(struct ak4114 *chip) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	chip->init = 1;	/* don't schedule new work */ | 
					
						
							|  |  |  | 	mb(); | 
					
						
							| 
									
										
										
										
											2010-12-11 17:51:26 +01:00
										 |  |  | 	cancel_delayed_work_sync(&chip->work); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	kfree(chip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_dev_free(struct snd_device *device) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = device->device_data; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	snd_ak4114_free(chip); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | int snd_ak4114_create(struct snd_card *card, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		      ak4114_read_t *read, ak4114_write_t *write, | 
					
						
							| 
									
										
										
										
											2013-10-29 16:37:11 +01:00
										 |  |  | 		      const unsigned char pgm[6], const unsigned char txcsb[5], | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 		      void *private_data, struct ak4114 **r_ak4114) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	int err = 0; | 
					
						
							|  |  |  | 	unsigned char reg; | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	static struct snd_device_ops ops = { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.dev_free =     snd_ak4114_dev_free, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
											
										 
											2005-09-09 14:22:34 +02:00
										 |  |  | 	chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (chip == NULL) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	spin_lock_init(&chip->lock); | 
					
						
							|  |  |  | 	chip->card = card; | 
					
						
							|  |  |  | 	chip->read = read; | 
					
						
							|  |  |  | 	chip->write = write; | 
					
						
							|  |  |  | 	chip->private_data = private_data; | 
					
						
							| 
									
										
										
										
											2007-01-31 14:34:38 +01:00
										 |  |  | 	INIT_DELAYED_WORK(&chip->work, ak4114_stats); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 16:37:11 +01:00
										 |  |  | 	for (reg = 0; reg < 6; reg++) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		chip->regmap[reg] = pgm[reg]; | 
					
						
							|  |  |  | 	for (reg = 0; reg < 5; reg++) | 
					
						
							|  |  |  | 		chip->txcsb[reg] = txcsb[reg]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 	ak4114_init_regs(chip); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); | 
					
						
							|  |  |  | 	chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 11:18:23 +01:00
										 |  |  | 	if ((err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops)) < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto __fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (r_ak4114) | 
					
						
							|  |  |  | 		*r_ak4114 = chip; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       __fail: | 
					
						
							|  |  |  | 	snd_ak4114_free(chip); | 
					
						
							|  |  |  | 	return err < 0 ? err : -EIO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned char mask, unsigned char val) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (reg <= AK4114_REG_INT1_MASK) | 
					
						
							|  |  |  | 		reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); | 
					
						
							|  |  |  | 	else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4) | 
					
						
							| 
									
										
										
										
											2007-02-05 13:07:04 +01:00
										 |  |  | 		reg_write(chip, reg, | 
					
						
							|  |  |  | 			  (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | static void ak4114_init_regs(struct ak4114 *chip) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* bring the chip to reset state and powerdown state */ | 
					
						
							|  |  |  | 	reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); | 
					
						
							|  |  |  | 	udelay(200); | 
					
						
							|  |  |  | 	/* release reset, but leave powerdown */ | 
					
						
							|  |  |  | 	reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); | 
					
						
							|  |  |  | 	udelay(200); | 
					
						
							| 
									
										
										
										
											2013-10-29 16:37:11 +01:00
										 |  |  | 	for (reg = 1; reg < 6; reg++) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		reg_write(chip, reg, chip->regmap[reg]); | 
					
						
							|  |  |  | 	for (reg = 0; reg < 5; reg++) | 
					
						
							|  |  |  | 		reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); | 
					
						
							|  |  |  | 	/* release powerdown, everything is initialized now */ | 
					
						
							|  |  |  | 	reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void snd_ak4114_reinit(struct ak4114 *chip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	chip->init = 1; | 
					
						
							|  |  |  | 	mb(); | 
					
						
							| 
									
										
										
										
											2012-08-20 14:51:24 -07:00
										 |  |  | 	flush_delayed_work(&chip->work); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 	ak4114_init_regs(chip); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* bring up statistics / event queing */ | 
					
						
							|  |  |  | 	chip->init = 0; | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 	if (chip->kctls[0]) | 
					
						
							|  |  |  | 		schedule_delayed_work(&chip->work, HZ / 10); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static unsigned int external_rate(unsigned char rcs1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (rcs1 & (AK4114_FS0|AK4114_FS1|AK4114_FS2|AK4114_FS3)) { | 
					
						
							|  |  |  | 	case AK4114_FS_32000HZ: return 32000; | 
					
						
							|  |  |  | 	case AK4114_FS_44100HZ: return 44100; | 
					
						
							|  |  |  | 	case AK4114_FS_48000HZ: return 48000; | 
					
						
							|  |  |  | 	case AK4114_FS_88200HZ: return 88200; | 
					
						
							|  |  |  | 	case AK4114_FS_96000HZ: return 96000; | 
					
						
							|  |  |  | 	case AK4114_FS_176400HZ: return 176400; | 
					
						
							|  |  |  | 	case AK4114_FS_192000HZ: return 192000; | 
					
						
							|  |  |  | 	default:		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_in_error_info(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				    struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
					
						
							|  |  |  | 	uinfo->count = 1; | 
					
						
							|  |  |  | 	uinfo->value.integer.min = 0; | 
					
						
							|  |  |  | 	uinfo->value.integer.max = LONG_MAX; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_in_error_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				   struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	long *ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irq(&chip->lock); | 
					
						
							|  |  |  | 	ptr = (long *)(((char *)chip) + kcontrol->private_value); | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[0] = *ptr; | 
					
						
							|  |  |  | 	*ptr = 0; | 
					
						
							|  |  |  | 	spin_unlock_irq(&chip->lock); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-23 15:42:26 +02:00
										 |  |  | #define snd_ak4114_in_bit_info		snd_ctl_boolean_mono_info
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_in_bit_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				 struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned char reg = kcontrol->private_value & 0xff; | 
					
						
							|  |  |  | 	unsigned char bit = (kcontrol->private_value >> 8) & 0xff; | 
					
						
							|  |  |  | 	unsigned char inv = (kcontrol->private_value >> 31) & 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_rate_info(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
					
						
							|  |  |  | 	uinfo->count = 1; | 
					
						
							|  |  |  | 	uinfo->value.integer.min = 0; | 
					
						
							|  |  |  | 	uinfo->value.integer.max = 192000; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_rate_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 			       struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1)); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | 
					
						
							|  |  |  | 	uinfo->count = 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < AK4114_REG_RXCSB_SIZE; i++) | 
					
						
							|  |  |  | 		ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_playback_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 					 struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) | 
					
						
							|  |  |  | 		ucontrol->value.iec958.status[i] = chip->txcsb[i]; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_playback_put(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 					 struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) | 
					
						
							|  |  |  | 		reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | 
					
						
							|  |  |  | 	uinfo->count = 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_mask_get(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				      struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_pinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
					
						
							|  |  |  | 	uinfo->value.integer.min = 0; | 
					
						
							|  |  |  | 	uinfo->value.integer.max = 0xffff; | 
					
						
							|  |  |  | 	uinfo->count = 4; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_pget(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				 struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned short tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[0] = 0xf8f2; | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[1] = 0x4e1f; | 
					
						
							|  |  |  | 	tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8); | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[2] = tmp; | 
					
						
							|  |  |  | 	tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8); | 
					
						
							|  |  |  | 	ucontrol->value.integer.value[3] = tmp; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_qinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; | 
					
						
							|  |  |  | 	uinfo->count = AK4114_REG_QSUB_SIZE; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static int snd_ak4114_spdif_qget(struct snd_kcontrol *kcontrol, | 
					
						
							|  |  |  | 				 struct snd_ctl_elem_value *ucontrol) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct ak4114 *chip = snd_kcontrol_chip(kcontrol); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < AK4114_REG_QSUB_SIZE; i++) | 
					
						
							|  |  |  | 		ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Don't forget to change AK4114_CONTROLS define!!! */ | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 Parity Errors", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_error_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_error_get, | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	.private_value = offsetof(struct ak4114, parity_errors), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 V-Bit Errors", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_error_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_error_get, | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	.private_value = offsetof(struct ak4114, v_bit_errors), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 C-CRC Errors", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_error_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_error_get, | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	.private_value = offsetof(struct ak4114, ccrc_errors), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 Q-CRC Errors", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_error_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_error_get, | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	.private_value = offsetof(struct ak4114, qcrc_errors), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 External Rate", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_rate_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_rate_get, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_mask_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_mask_get, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_playback_get, | 
					
						
							|  |  |  | 	.put =		snd_ak4114_spdif_playback_put, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_mask_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_mask_get, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_get, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							| 
									
										
										
										
											2012-11-02 00:28:50 +09:00
										 |  |  | 	.name =		"IEC958 Preamble Capture Default", | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_pinfo, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_pget, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 Q-subcode Capture Default", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_spdif_qinfo, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_spdif_qget, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 Audio", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_bit_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_bit_get, | 
					
						
							|  |  |  | 	.private_value = (1<<31) | (1<<8) | AK4114_REG_RCS0, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 Non-PCM Bitstream", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_bit_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_bit_get, | 
					
						
							| 
									
										
										
										
											2007-04-05 17:07:30 +02:00
										 |  |  | 	.private_value = (6<<8) | AK4114_REG_RCS0, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 DTS Bitstream", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_bit_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_bit_get, | 
					
						
							| 
									
										
										
										
											2007-04-05 17:07:30 +02:00
										 |  |  | 	.private_value = (3<<8) | AK4114_REG_RCS0, | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM, | 
					
						
							|  |  |  | 	.name =		"IEC958 PPL Lock Status", | 
					
						
							|  |  |  | 	.access =	SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | 
					
						
							|  |  |  | 	.info =		snd_ak4114_in_bit_info, | 
					
						
							|  |  |  | 	.get =		snd_ak4114_in_bit_get, | 
					
						
							|  |  |  | 	.private_value = (1<<31) | (4<<8) | AK4114_REG_RCS0, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-11 14:48:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void snd_ak4114_proc_regs_read(struct snd_info_entry *entry, | 
					
						
							|  |  |  | 		struct snd_info_buffer *buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ak4114 *ak4114 = entry->private_data; | 
					
						
							|  |  |  | 	int reg, val; | 
					
						
							|  |  |  | 	/* all ak4114 registers 0x00 - 0x1f */ | 
					
						
							|  |  |  | 	for (reg = 0; reg < 0x20; reg++) { | 
					
						
							|  |  |  | 		val = reg_read(ak4114, reg); | 
					
						
							|  |  |  | 		snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void snd_ak4114_proc_init(struct ak4114 *ak4114) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct snd_info_entry *entry; | 
					
						
							|  |  |  | 	if (!snd_card_proc_new(ak4114->card, "ak4114", &entry)) | 
					
						
							|  |  |  | 		snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | int snd_ak4114_build(struct ak4114 *ak4114, | 
					
						
							|  |  |  | 		     struct snd_pcm_substream *ply_substream, | 
					
						
							|  |  |  | 		     struct snd_pcm_substream *cap_substream) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct snd_kcontrol *kctl; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned int idx; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-08 17:12:47 +02:00
										 |  |  | 	if (snd_BUG_ON(!cap_substream)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ak4114->playback_substream = ply_substream; | 
					
						
							|  |  |  | 	ak4114->capture_substream = cap_substream; | 
					
						
							|  |  |  | 	for (idx = 0; idx < AK4114_CONTROLS; idx++) { | 
					
						
							|  |  |  | 		kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114); | 
					
						
							|  |  |  | 		if (kctl == NULL) | 
					
						
							|  |  |  | 			return -ENOMEM; | 
					
						
							| 
									
										
										
										
											2007-04-05 17:07:30 +02:00
										 |  |  | 		if (strstr(kctl->id.name, "Playback")) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (ply_substream == NULL) { | 
					
						
							|  |  |  | 				snd_ctl_free_one(kctl); | 
					
						
							|  |  |  | 				ak4114->kctls[idx] = NULL; | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			kctl->id.device = ply_substream->pcm->device; | 
					
						
							|  |  |  | 			kctl->id.subdevice = ply_substream->number; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			kctl->id.device = cap_substream->pcm->device; | 
					
						
							|  |  |  | 			kctl->id.subdevice = cap_substream->number; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		err = snd_ctl_add(ak4114->card, kctl); | 
					
						
							|  |  |  | 		if (err < 0) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 		ak4114->kctls[idx] = kctl; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-11 14:48:06 +01:00
										 |  |  | 	snd_ak4114_proc_init(ak4114); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 	/* trigger workq */ | 
					
						
							|  |  |  | 	schedule_delayed_work(&ak4114->work, HZ / 10); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | /* notify kcontrols if any parameters are changed */ | 
					
						
							|  |  |  | static void ak4114_notify(struct ak4114 *ak4114, | 
					
						
							|  |  |  | 			  unsigned char rcs0, unsigned char rcs1, | 
					
						
							|  |  |  | 			  unsigned char c0, unsigned char c1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!ak4114->kctls[0]) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rcs0 & AK4114_PAR) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[0]->id); | 
					
						
							|  |  |  | 	if (rcs0 & AK4114_V) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[1]->id); | 
					
						
							|  |  |  | 	if (rcs1 & AK4114_CCRC) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[2]->id); | 
					
						
							|  |  |  | 	if (rcs1 & AK4114_QCRC) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[3]->id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* rate change */ | 
					
						
							|  |  |  | 	if (c1 & 0xf0) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[4]->id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT)) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[9]->id); | 
					
						
							|  |  |  | 	if (c0 & AK4114_QINT) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[10]->id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (c0 & AK4114_AUDION) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[11]->id); | 
					
						
							|  |  |  | 	if (c0 & AK4114_AUTO) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[12]->id); | 
					
						
							|  |  |  | 	if (c0 & AK4114_DTSCD) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[13]->id); | 
					
						
							| 
									
										
										
										
											2007-04-05 17:07:30 +02:00
										 |  |  | 	if (c0 & AK4114_UNLCK) | 
					
						
							|  |  |  | 		snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
					
						
							|  |  |  | 			       &ak4114->kctls[14]->id); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | int snd_ak4114_external_rate(struct ak4114 *ak4114) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned char rcs1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rcs1 = reg_read(ak4114, AK4114_REG_RCS1); | 
					
						
							|  |  |  | 	return external_rate(rcs1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-17 14:17:19 +01:00
										 |  |  | 	struct snd_pcm_runtime *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime : NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned long _flags; | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							|  |  |  | 	unsigned char rcs0, rcs1; | 
					
						
							|  |  |  | 	unsigned char c0, c1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rcs1 = reg_read(ak4114, AK4114_REG_RCS1); | 
					
						
							|  |  |  | 	if (flags & AK4114_CHECK_NO_STAT) | 
					
						
							|  |  |  | 		goto __rate; | 
					
						
							|  |  |  | 	rcs0 = reg_read(ak4114, AK4114_REG_RCS0); | 
					
						
							|  |  |  | 	spin_lock_irqsave(&ak4114->lock, _flags); | 
					
						
							|  |  |  | 	if (rcs0 & AK4114_PAR) | 
					
						
							|  |  |  | 		ak4114->parity_errors++; | 
					
						
							|  |  |  | 	if (rcs1 & AK4114_V) | 
					
						
							|  |  |  | 		ak4114->v_bit_errors++; | 
					
						
							|  |  |  | 	if (rcs1 & AK4114_CCRC) | 
					
						
							|  |  |  | 		ak4114->ccrc_errors++; | 
					
						
							|  |  |  | 	if (rcs1 & AK4114_QCRC) | 
					
						
							|  |  |  | 		ak4114->qcrc_errors++; | 
					
						
							|  |  |  | 	c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^ | 
					
						
							|  |  |  |                      (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)); | 
					
						
							|  |  |  | 	c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); | 
					
						
							|  |  |  | 	ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT); | 
					
						
							|  |  |  | 	ak4114->rcs1 = rcs1; | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ak4114->lock, _flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 	ak4114_notify(ak4114, rcs0, rcs1, c0, c1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (ak4114->change_callback && (c0 | c1) != 0) | 
					
						
							|  |  |  | 		ak4114->change_callback(ak4114, c0, c1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       __rate: | 
					
						
							|  |  |  | 	/* compare rate */ | 
					
						
							|  |  |  | 	res = external_rate(rcs1); | 
					
						
							|  |  |  | 	if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { | 
					
						
							|  |  |  | 		snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); | 
					
						
							|  |  |  | 		if (snd_pcm_running(ak4114->capture_substream)) { | 
					
						
							| 
									
										
										
										
											2005-10-20 18:26:44 +02:00
										 |  |  | 			// printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res);
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); | 
					
						
							|  |  |  | 			res = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-22 14:57:56 +00:00
										 |  |  | static void ak4114_stats(struct work_struct *work) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-11-22 14:57:56 +00:00
										 |  |  | 	struct ak4114 *chip = container_of(work, struct ak4114, work.work); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-05 17:07:30 +02:00
										 |  |  | 	if (!chip->init) | 
					
						
							| 
									
										
										
										
											2008-03-17 08:45:33 +01:00
										 |  |  | 		snd_ak4114_check_rate_and_errors(chip, chip->check_flags); | 
					
						
							| 
									
										
										
										
											2007-03-30 15:38:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-19 17:13:16 +01:00
										 |  |  | 	schedule_delayed_work(&chip->work, HZ / 10); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_create); | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_reg_write); | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_reinit); | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_build); | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_external_rate); | 
					
						
							|  |  |  | EXPORT_SYMBOL(snd_ak4114_check_rate_and_errors); |