aboutsummaryrefslogtreecommitdiff
path: root/sound/i2c/other
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/i2c/other
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/i2c/other')
-rw-r--r--sound/i2c/other/Makefile16
-rw-r--r--sound/i2c/other/ak4114.c580
-rw-r--r--sound/i2c/other/ak4117.c559
-rw-r--r--sound/i2c/other/ak4xxx-adda.c501
-rw-r--r--sound/i2c/other/tea575x-tuner.c233
5 files changed, 1889 insertions, 0 deletions
diff --git a/sound/i2c/other/Makefile b/sound/i2c/other/Makefile
new file mode 100644
index 00000000000..2fe023ef00a
--- /dev/null
+++ b/sound/i2c/other/Makefile
@@ -0,0 +1,16 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-ak4114-objs := ak4114.o
+snd-ak4117-objs := ak4117.o
+snd-ak4xxx-adda-objs := ak4xxx-adda.o
+snd-tea575x-tuner-objs := tea575x-tuner.o
+
+# Module Dependency
+obj-$(CONFIG_SND_PDAUDIOCF) += snd-ak4117.o
+obj-$(CONFIG_SND_ICE1712) += snd-ak4xxx-adda.o
+obj-$(CONFIG_SND_ICE1724) += snd-ak4xxx-adda.o
+obj-$(CONFIG_SND_ICE1724) += snd-ak4114.o
+obj-$(CONFIG_SND_FM801_TEA575X) += snd-tea575x-tuner.o
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
new file mode 100644
index 00000000000..f5e6018ea3f
--- /dev/null
+++ b/sound/i2c/other/ak4114.c
@@ -0,0 +1,580 @@
+/*
+ * Routines for control of the AK4114 via I2C and 4-wire serial interface
+ * IEC958 (S/PDIF) receiver by Asahi Kasei
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * 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 <sound/driver.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/ak4114.h>
+#include <sound/asoundef.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
+MODULE_LICENSE("GPL");
+
+#define AK4114_ADDR 0x00 /* fixed address */
+
+static void ak4114_stats(void *);
+
+static void reg_write(ak4114_t *ak4114, unsigned char reg, unsigned char val)
+{
+ ak4114->write(ak4114->private_data, reg, val);
+ if (reg <= AK4114_REG_INT1_MASK)
+ ak4114->regmap[reg] = val;
+ else if (reg >= AK4114_REG_RXCSB0 && reg <= AK4114_REG_TXCSB4)
+ ak4114->txcsb[reg-AK4114_REG_RXCSB0] = val;
+}
+
+static inline unsigned char reg_read(ak4114_t *ak4114, unsigned char reg)
+{
+ return ak4114->read(ak4114->private_data, reg);
+}
+
+#if 0
+static void reg_dump(ak4114_t *ak4114)
+{
+ int i;
+
+ printk("AK4114 REG DUMP:\n");
+ for (i = 0; i < 0x20; i++)
+ printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0);
+}
+#endif
+
+static void snd_ak4114_free(ak4114_t *chip)
+{
+ chip->init = 1; /* don't schedule new work */
+ mb();
+ if (chip->workqueue != NULL) {
+ flush_workqueue(chip->workqueue);
+ destroy_workqueue(chip->workqueue);
+ }
+ kfree(chip);
+}
+
+static int snd_ak4114_dev_free(snd_device_t *device)
+{
+ ak4114_t *chip = device->device_data;
+ snd_ak4114_free(chip);
+ return 0;
+}
+
+int snd_ak4114_create(snd_card_t *card,
+ ak4114_read_t *read, ak4114_write_t *write,
+ unsigned char pgm[7], unsigned char txcsb[5],
+ void *private_data, ak4114_t **r_ak4114)
+{
+ ak4114_t *chip;
+ int err = 0;
+ unsigned char reg;
+ static snd_device_ops_t ops = {
+ .dev_free = snd_ak4114_dev_free,
+ };
+
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ spin_lock_init(&chip->lock);
+ chip->card = card;
+ chip->read = read;
+ chip->write = write;
+ chip->private_data = private_data;
+
+ for (reg = 0; reg < 7; reg++)
+ chip->regmap[reg] = pgm[reg];
+ for (reg = 0; reg < 5; reg++)
+ chip->txcsb[reg] = txcsb[reg];
+
+ chip->workqueue = create_workqueue("snd-ak4114");
+ if (chip->workqueue == NULL) {
+ kfree(chip);
+ return -ENOMEM;
+ }
+
+ snd_ak4114_reinit(chip);
+
+ chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT);
+ chip->rcs1 = reg_read(chip, AK4114_REG_RCS1);
+
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
+ goto __fail;
+
+ if (r_ak4114)
+ *r_ak4114 = chip;
+ return 0;
+
+ __fail:
+ snd_ak4114_free(chip);
+ return err < 0 ? err : -EIO;
+}
+
+void snd_ak4114_reg_write(ak4114_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
+{
+ 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)
+ reg_write(chip, reg, (chip->txcsb[reg] & ~mask) | val);
+}
+
+void snd_ak4114_reinit(ak4114_t *chip)
+{
+ unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg;
+
+ chip->init = 1;
+ mb();
+ flush_workqueue(chip->workqueue);
+ /* 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);
+ for (reg = 1; reg < 7; reg++)
+ 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);
+ /* bring up statistics / event queing */
+ chip->init = 0;
+ INIT_WORK(&chip->work, ak4114_stats, chip);
+ queue_delayed_work(chip->workqueue, &chip->work, HZ / 10);
+}
+
+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;
+ }
+}
+
+static int snd_ak4114_in_error_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = LONG_MAX;
+ return 0;
+}
+
+static int snd_ak4114_in_error_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4114_in_bit_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_ak4114_in_bit_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4114_rate_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 192000;
+ return 0;
+}
+
+static int snd_ak4114_rate_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+
+ ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1));
+ return 0;
+}
+
+static int snd_ak4114_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+ uinfo->count = 1;
+ return 0;
+}
+
+static int snd_ak4114_spdif_get(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4114_spdif_playback_get(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned i;
+
+ for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++)
+ ucontrol->value.iec958.status[i] = chip->txcsb[i];
+ return 0;
+}
+
+static int snd_ak4114_spdif_playback_put(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4114_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+ uinfo->count = 1;
+ return 0;
+}
+
+static int snd_ak4114_spdif_mask_get(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE);
+ return 0;
+}
+
+static int snd_ak4114_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 0xffff;
+ uinfo->count = 4;
+ return 0;
+}
+
+static int snd_ak4114_spdif_pget(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4114_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+ uinfo->count = AK4114_REG_QSUB_SIZE;
+ return 0;
+}
+
+static int snd_ak4114_spdif_qget(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4114_t *chip = snd_kcontrol_chip(kcontrol);
+ 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!!! */
+static snd_kcontrol_new_t snd_ak4114_iec958_controls[] = {
+{
+ .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,
+ .private_value = offsetof(ak4114_t, parity_errors),
+},
+{
+ .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,
+ .private_value = offsetof(ak4114_t, v_bit_errors),
+},
+{
+ .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,
+ .private_value = offsetof(ak4114_t, ccrc_errors),
+},
+{
+ .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,
+ .private_value = offsetof(ak4114_t, qcrc_errors),
+},
+{
+ .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,
+ .name = "IEC958 Preample Capture Default",
+ .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,
+ .private_value = (6<<8) | AK4114_REG_RCS1,
+},
+{
+ .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,
+ .private_value = (3<<8) | AK4114_REG_RCS1,
+}
+};
+
+int snd_ak4114_build(ak4114_t *ak4114,
+ snd_pcm_substream_t *ply_substream,
+ snd_pcm_substream_t *cap_substream)
+{
+ snd_kcontrol_t *kctl;
+ unsigned int idx;
+ int err;
+
+ snd_assert(cap_substream, return -EINVAL);
+ 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;
+ if (!strstr(kctl->id.name, "Playback")) {
+ 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;
+ }
+ return 0;
+}
+
+int snd_ak4114_external_rate(ak4114_t *ak4114)
+{
+ unsigned char rcs1;
+
+ rcs1 = reg_read(ak4114, AK4114_REG_RCS1);
+ return external_rate(rcs1);
+}
+
+int snd_ak4114_check_rate_and_errors(ak4114_t *ak4114, unsigned int flags)
+{
+ snd_pcm_runtime_t *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime : NULL;
+ 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);
+
+ 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);
+
+ 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)) {
+ // printk("rate changed (%i <- %i)\n", runtime->rate, res);
+ snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING);
+ wake_up(&runtime->sleep);
+ res = 1;
+ }
+ snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags);
+ }
+ return res;
+}
+
+static void ak4114_stats(void *data)
+{
+ ak4114_t *chip = (ak4114_t *)data;
+
+ if (chip->init)
+ return;
+ snd_ak4114_check_rate_and_errors(chip, 0);
+ queue_delayed_work(chip->workqueue, &chip->work, HZ / 10);
+}
+
+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);
diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c
new file mode 100644
index 00000000000..0419c4336a5
--- /dev/null
+++ b/sound/i2c/other/ak4117.c
@@ -0,0 +1,559 @@
+/*
+ * Routines for control of the AK4117 via 4-wire serial interface
+ * IEC958 (S/PDIF) receiver by Asahi Kasei
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * 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 <sound/driver.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/ak4117.h>
+#include <sound/asoundef.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("AK4117 IEC958 (S/PDIF) receiver by Asahi Kasei");
+MODULE_LICENSE("GPL");
+
+#define AK4117_ADDR 0x00 /* fixed address */
+
+static void snd_ak4117_timer(unsigned long data);
+
+static void reg_write(ak4117_t *ak4117, unsigned char reg, unsigned char val)
+{
+ ak4117->write(ak4117->private_data, reg, val);
+ if (reg < sizeof(ak4117->regmap))
+ ak4117->regmap[reg] = val;
+}
+
+static inline unsigned char reg_read(ak4117_t *ak4117, unsigned char reg)
+{
+ return ak4117->read(ak4117->private_data, reg);
+}
+
+#if 0
+static void reg_dump(ak4117_t *ak4117)
+{
+ int i;
+
+ printk("AK4117 REG DUMP:\n");
+ for (i = 0; i < 0x1b; i++)
+ printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0);
+}
+#endif
+
+static void snd_ak4117_free(ak4117_t *chip)
+{
+ del_timer(&chip->timer);
+ kfree(chip);
+}
+
+static int snd_ak4117_dev_free(snd_device_t *device)
+{
+ ak4117_t *chip = device->device_data;
+ snd_ak4117_free(chip);
+ return 0;
+}
+
+int snd_ak4117_create(snd_card_t *card, ak4117_read_t *read, ak4117_write_t *write,
+ unsigned char pgm[5], void *private_data, ak4117_t **r_ak4117)
+{
+ ak4117_t *chip;
+ int err = 0;
+ unsigned char reg;
+ static snd_device_ops_t ops = {
+ .dev_free = snd_ak4117_dev_free,
+ };
+
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ spin_lock_init(&chip->lock);
+ chip->card = card;
+ chip->read = read;
+ chip->write = write;
+ chip->private_data = private_data;
+ init_timer(&chip->timer);
+ chip->timer.data = (unsigned long)chip;
+ chip->timer.function = snd_ak4117_timer;
+
+ for (reg = 0; reg < 5; reg++)
+ chip->regmap[reg] = pgm[reg];
+ snd_ak4117_reinit(chip);
+
+ chip->rcs0 = reg_read(chip, AK4117_REG_RCS0) & ~(AK4117_QINT | AK4117_CINT | AK4117_STC);
+ chip->rcs1 = reg_read(chip, AK4117_REG_RCS1);
+ chip->rcs2 = reg_read(chip, AK4117_REG_RCS2);
+
+ if ((err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops)) < 0)
+ goto __fail;
+
+ if (r_ak4117)
+ *r_ak4117 = chip;
+ return 0;
+
+ __fail:
+ snd_ak4117_free(chip);
+ return err < 0 ? err : -EIO;
+}
+
+void snd_ak4117_reg_write(ak4117_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
+{
+ if (reg >= 5)
+ return;
+ reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
+}
+
+void snd_ak4117_reinit(ak4117_t *chip)
+{
+ unsigned char old = chip->regmap[AK4117_REG_PWRDN], reg;
+
+ del_timer(&chip->timer);
+ chip->init = 1;
+ /* bring the chip to reset state and powerdown state */
+ reg_write(chip, AK4117_REG_PWRDN, 0);
+ udelay(200);
+ /* release reset, but leave powerdown */
+ reg_write(chip, AK4117_REG_PWRDN, (old | AK4117_RST) & ~AK4117_PWN);
+ udelay(200);
+ for (reg = 1; reg < 5; reg++)
+ reg_write(chip, reg, chip->regmap[reg]);
+ /* release powerdown, everything is initialized now */
+ reg_write(chip, AK4117_REG_PWRDN, old | AK4117_RST | AK4117_PWN);
+ chip->init = 0;
+ chip->timer.expires = 1 + jiffies;
+ add_timer(&chip->timer);
+}
+
+static unsigned int external_rate(unsigned char rcs1)
+{
+ switch (rcs1 & (AK4117_FS0|AK4117_FS1|AK4117_FS2|AK4117_FS3)) {
+ case AK4117_FS_32000HZ: return 32000;
+ case AK4117_FS_44100HZ: return 44100;
+ case AK4117_FS_48000HZ: return 48000;
+ case AK4117_FS_88200HZ: return 88200;
+ case AK4117_FS_96000HZ: return 96000;
+ case AK4117_FS_176400HZ: return 176400;
+ case AK4117_FS_192000HZ: return 192000;
+ default: return 0;
+ }
+}
+
+static int snd_ak4117_in_error_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = LONG_MAX;
+ return 0;
+}
+
+static int snd_ak4117_in_error_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4117_in_bit_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_ak4117_in_bit_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ 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;
+}
+
+static int snd_ak4117_rx_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_ak4117_rx_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+
+ ucontrol->value.integer.value[0] = (chip->regmap[AK4117_REG_IO] & AK4117_IPS) ? 1 : 0;
+ return 0;
+}
+
+static int snd_ak4117_rx_put(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ int change;
+ u8 old_val;
+
+ spin_lock_irq(&chip->lock);
+ old_val = chip->regmap[AK4117_REG_IO];
+ change = !!ucontrol->value.integer.value[0] != ((old_val & AK4117_IPS) ? 1 : 0);
+ if (change)
+ reg_write(chip, AK4117_REG_IO, (old_val & ~AK4117_IPS) | (ucontrol->value.integer.value[0] ? AK4117_IPS : 0));
+ spin_unlock_irq(&chip->lock);
+ return change;
+}
+
+static int snd_ak4117_rate_info(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_info_t *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 192000;
+ return 0;
+}
+
+static int snd_ak4117_rate_get(snd_kcontrol_t *kcontrol,
+ snd_ctl_elem_value_t *ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+
+ ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4117_REG_RCS1));
+ return 0;
+}
+
+static int snd_ak4117_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+ uinfo->count = 1;
+ return 0;
+}
+
+static int snd_ak4117_spdif_get(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned i;
+
+ for (i = 0; i < AK4117_REG_RXCSB_SIZE; i++)
+ ucontrol->value.iec958.status[i] = reg_read(chip, AK4117_REG_RXCSB0 + i);
+ return 0;
+}
+
+static int snd_ak4117_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+ uinfo->count = 1;
+ return 0;
+}
+
+static int snd_ak4117_spdif_mask_get(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ memset(ucontrol->value.iec958.status, 0xff, AK4117_REG_RXCSB_SIZE);
+ return 0;
+}
+
+static int snd_ak4117_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 0xffff;
+ uinfo->count = 4;
+ return 0;
+}
+
+static int snd_ak4117_spdif_pget(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned short tmp;
+
+ ucontrol->value.integer.value[0] = 0xf8f2;
+ ucontrol->value.integer.value[1] = 0x4e1f;
+ tmp = reg_read(chip, AK4117_REG_Pc0) | (reg_read(chip, AK4117_REG_Pc1) << 8);
+ ucontrol->value.integer.value[2] = tmp;
+ tmp = reg_read(chip, AK4117_REG_Pd0) | (reg_read(chip, AK4117_REG_Pd1) << 8);
+ ucontrol->value.integer.value[3] = tmp;
+ return 0;
+}
+
+static int snd_ak4117_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+ uinfo->count = AK4117_REG_QSUB_SIZE;
+ return 0;
+}
+
+static int snd_ak4117_spdif_qget(snd_kcontrol_t * kcontrol,
+ snd_ctl_elem_value_t * ucontrol)
+{
+ ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned i;
+
+ for (i = 0; i < AK4117_REG_QSUB_SIZE; i++)
+ ucontrol->value.bytes.data[i] = reg_read(chip, AK4117_REG_QSUB_ADDR + i);
+ return 0;
+}
+
+/* Don't forget to change AK4117_CONTROLS define!!! */
+static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 Parity Errors",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_error_info,
+ .get = snd_ak4117_in_error_get,
+ .private_value = offsetof(ak4117_t, parity_errors),
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 V-Bit Errors",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_error_info,
+ .get = snd_ak4117_in_error_get,
+ .private_value = offsetof(ak4117_t, v_bit_errors),
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 C-CRC Errors",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_error_info,
+ .get = snd_ak4117_in_error_get,
+ .private_value = offsetof(ak4117_t, ccrc_errors),
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 Q-CRC Errors",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_error_info,
+ .get = snd_ak4117_in_error_get,
+ .private_value = offsetof(ak4117_t, qcrc_errors),
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 External Rate",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_rate_info,
+ .get = snd_ak4117_rate_get,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
+ .access = SNDRV_CTL_ELEM_ACCESS_READ,
+ .info = snd_ak4117_spdif_mask_info,
+ .get = snd_ak4117_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_ak4117_spdif_info,
+ .get = snd_ak4117_spdif_get,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 Preample Capture Default",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_spdif_pinfo,
+ .get = snd_ak4117_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_ak4117_spdif_qinfo,
+ .get = snd_ak4117_spdif_qget,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 Audio",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_bit_info,
+ .get = snd_ak4117_in_bit_get,
+ .private_value = (1<<31) | (3<<8) | AK4117_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_ak4117_in_bit_info,
+ .get = snd_ak4117_in_bit_get,
+ .private_value = (5<<8) | AK4117_REG_RCS1,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "IEC958 DTS Bitstream",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = snd_ak4117_in_bit_info,
+ .get = snd_ak4117_in_bit_get,
+ .private_value = (6<<8) | AK4117_REG_RCS1,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = "AK4117 Input Select",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE,
+ .info = snd_ak4117_rx_info,
+ .get = snd_ak4117_rx_get,
+ .put = snd_ak4117_rx_put,
+}
+};
+
+int snd_ak4117_build(ak4117_t *ak4117, snd_pcm_substream_t *cap_substream)
+{
+ snd_kcontrol_t *kctl;
+ unsigned int idx;
+ int err;
+
+ snd_assert(cap_substream, return -EINVAL);
+ ak4117->substream = cap_substream;
+ for (idx = 0; idx < AK4117_CONTROLS; idx++) {
+ kctl = snd_ctl_new1(&snd_ak4117_iec958_controls[idx], ak4117);
+ if (kctl == NULL)
+ return -ENOMEM;
+ kctl->id.device = cap_substream->pcm->device;
+ kctl->id.subdevice = cap_substream->number;
+ err = snd_ctl_add(ak4117->card, kctl);
+ if (err < 0)
+ return err;
+ ak4117->kctls[idx] = kctl;
+ }
+ return 0;
+}
+
+int snd_ak4117_external_rate(ak4117_t *ak4117)
+{
+ unsigned char rcs1;
+
+ rcs1 = reg_read(ak4117, AK4117_REG_RCS1);
+ return external_rate(rcs1);
+}
+
+int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
+{
+ snd_pcm_runtime_t *runtime = ak4117->substream ? ak4117->substream->runtime : NULL;
+ unsigned long _flags;
+ int res = 0;
+ unsigned char rcs0, rcs1, rcs2;
+ unsigned char c0, c1;
+
+ rcs1 = reg_read(ak4117, AK4117_REG_RCS1);
+ if (flags & AK4117_CHECK_NO_STAT)
+ goto __rate;
+ rcs0 = reg_read(ak4117, AK4117_REG_RCS0);
+ rcs2 = reg_read(ak4117, AK4117_REG_RCS2);
+ // printk("AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2);
+ spin_lock_irqsave(&ak4117->lock, _flags);
+ if (rcs0 & AK4117_PAR)
+ ak4117->parity_errors++;
+ if (rcs0 & AK4117_V)
+ ak4117->v_bit_errors++;
+ if (rcs2 & AK4117_CCRC)
+ ak4117->ccrc_errors++;
+ if (rcs2 & AK4117_QCRC)
+ ak4117->qcrc_errors++;
+ c0 = (ak4117->rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)) ^
+ (rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK));
+ c1 = (ak4117->rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)) ^
+ (rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f));
+ ak4117->rcs0 = rcs0 & ~(AK4117_QINT | AK4117_CINT | AK4117_STC);
+ ak4117->rcs1 = rcs1;
+ ak4117->rcs2 = rcs2;
+ spin_unlock_irqrestore(&ak4117->lock, _flags);
+
+ if (rcs0 & AK4117_PAR)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[0]->id);
+ if (rcs0 & AK4117_V)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[1]->id);
+ if (rcs2 & AK4117_CCRC)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[2]->id);
+ if (rcs2 & AK4117_QCRC)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[3]->id);
+
+ /* rate change */
+ if (c1 & 0x0f)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[4]->id);
+
+ if ((c1 & AK4117_PEM) | (c0 & AK4117_CINT))
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[6]->id);
+ if (c0 & AK4117_QINT)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[8]->id);
+
+ if (c0 & AK4117_AUDION)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[9]->id);
+ if (c1 & AK4117_NPCM)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[10]->id);
+ if (c1 & AK4117_DTSCD)
+ snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[11]->id);
+
+ if (ak4117->change_callback && (c0 | c1) != 0)
+ ak4117->change_callback(ak4117, c0, c1);
+
+ __rate:
+ /* compare rate */
+ res = external_rate(rcs1);
+ if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) {
+ snd_pcm_stream_lock_irqsave(ak4117->substream, _flags);
+ if (snd_pcm_running(ak4117->substream)) {
+ // printk("rate changed (%i <- %i)\n", runtime->rate, res);
+ snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING);
+ wake_up(&runtime->sleep);
+ res = 1;
+ }
+ snd_pcm_stream_unlock_irqrestore(ak4117->substream, _flags);
+ }
+ return res;
+}
+
+static void snd_ak4117_timer(unsigned long data)
+{
+ ak4117_t *chip = (ak4117_t *)data;
+
+ if (chip->init)
+ return;
+ snd_ak4117_check_rate_and_errors(chip, 0);
+ chip->timer.expires = 1 + jiffies;
+ add_timer(&chip->timer);
+}
+
+EXPORT_SYMBOL(snd_ak4117_create);
+EXPORT_SYMBOL(snd_ak4117_reg_write);
+EXPORT_SYMBOL(snd_ak4117_reinit);
+EXPORT_SYMBOL(snd_ak4117_build);
+EXPORT_SYMBOL(snd_ak4117_external_rate);
+EXPORT_SYMBOL(snd_ak4117_check_rate_and_errors);
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
new file mode 100644
index 00000000000..db2b7274a9d
--- /dev/null
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -0,0 +1,501 @@
+/*
+ * ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
+ * AD and DA converters
+ *
+ * Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>,
+ * Takashi Iwai <tiwai@suse.de>
+ *
+ * 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 <sound/driver.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/ak4xxx-adda.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>");
+MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters");
+MODULE_LICENSE("GPL");
+
+void snd_akm4xxx_write(akm4xxx_t *ak, int chip, unsigned char reg, unsigned char val)
+{
+ ak->ops.lock(ak, chip);
+ ak->ops.write(ak, chip, reg, val);
+
+ /* save the data */
+ if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
+ if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
+ snd_akm4xxx_set(ak, chip, reg, val);
+ else
+ snd_akm4xxx_set_ipga(ak, chip, reg, val);
+ } else {
+ /* AK4529, or else */
+ snd_akm4xxx_set(ak, chip, reg, val);
+ }
+ ak->ops.unlock(ak, chip);
+}
+
+/*
+ * reset the AKM codecs
+ * @state: 1 = reset codec, 0 = restore the registers
+ *
+ * assert the reset operation and restores the register values to the chips.
+ */
+void snd_akm4xxx_reset(akm4xxx_t *ak, int state)
+{
+ unsigned int chip;
+ unsigned char reg;
+
+ switch (ak->type) {
+ case SND_AK4524:
+ case SND_AK4528:
+ for (chip = 0; chip < ak->num_dacs/2; chip++) {
+ snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
+ if (state)
+ continue;
+ /* DAC volumes */
+ for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
+ snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
+ if (ak->type == SND_AK4528)
+ continue;
+ /* IPGA */
+ for (reg = 0x04; reg < 0x06; reg++)
+ snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get_ipga(ak, chip, reg));
+ }
+ break;
+ case SND_AK4529:
+ /* FIXME: needed for ak4529? */
+ break;
+ case SND_AK4355:
+ case SND_AK4358:
+ if (state) {
+ snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
+ return;
+ }
+ for (reg = 0x00; reg < 0x0b; reg++)
+ if (reg != 0x01)
+ snd_akm4xxx_write(ak, 0, reg, snd_akm4xxx_get(ak, 0, reg));
+ snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
+ break;
+ case SND_AK4381:
+ for (chip = 0; chip < ak->num_dacs/2; chip++) {
+ snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
+ if (state)
+ continue;
+ for (reg = 0x01; reg < 0x05; reg++)
+ snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
+ }
+ break;
+ }
+}
+
+/*
+ * initialize all the ak4xxx chips
+ */
+void snd_akm4xxx_init(akm4xxx_t *ak)
+{
+ static unsigned char inits_ak4524[] = {
+ 0x00, 0x07, /* 0: all power up */
+ 0x01, 0x00, /* 1: ADC/DAC reset */
+ 0x02, 0x60, /* 2: 24bit I2S */
+ 0x03, 0x19, /* 3: deemphasis off */
+ 0x01, 0x03, /* 1: ADC/DAC enable */
+ 0x04, 0x00, /* 4: ADC left muted */
+ 0x05, 0x00, /* 5: ADC right muted */
+ 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
+ 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
+ 0x06, 0x00, /* 6: DAC left muted */
+ 0x07, 0x00, /* 7: DAC right muted */
+ 0xff, 0xff
+ };
+ static unsigned char inits_ak4528[] = {
+ 0x00, 0x07, /* 0: all power up */
+ 0x01, 0x00, /* 1: ADC/DAC reset */
+ 0x02, 0x60, /* 2: 24bit I2S */
+ 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
+ 0x01, 0x03, /* 1: ADC/DAC enable */
+ 0x04, 0x00, /* 4: ADC left muted */
+ 0x05, 0x00, /* 5: ADC right muted */
+ 0xff, 0xff
+ };
+ static unsigned char inits_ak4529[] = {
+ 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
+ 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
+ 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
+ 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
+ 0x02, 0xff, /* 2: LOUT1 muted */
+ 0x03, 0xff, /* 3: ROUT1 muted */
+ 0x04, 0xff, /* 4: LOUT2 muted */
+ 0x05, 0xff, /* 5: ROUT2 muted */
+ 0x06, 0xff, /* 6: LOUT3 muted */
+ 0x07, 0xff, /* 7: ROUT3 muted */
+ 0x0b, 0xff, /* B: LOUT4 muted */
+ 0x0c, 0xff, /* C: ROUT4 muted */
+ 0x08, 0x55, /* 8: deemphasis all off */
+ 0xff, 0xff
+ };
+ static unsigned char inits_ak4355[] = {
+ 0x01, 0x02, /* 1: reset and soft-mute */
+ 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
+ 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
+ // 0x02, 0x2e, /* quad speed */
+ 0x03, 0x01, /* 3: de-emphasis off */
+ 0x04, 0x00, /* 4: LOUT1 volume muted */
+ 0x05, 0x00, /* 5: ROUT1 volume muted */
+ 0x06, 0x00, /* 6: LOUT2 volume muted */
+ 0x07, 0x00, /* 7: ROUT2 volume muted */
+ 0x08, 0x00, /* 8: LOUT3 volume muted */
+ 0x09, 0x00, /* 9: ROUT3 volume muted */
+ 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
+ 0x01, 0x01, /* 1: un-reset, unmute */
+ 0xff, 0xff
+ };
+ static unsigned char inits_ak4358[] = {
+ 0x01, 0x02, /* 1: reset and soft-mute */
+ 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
+ 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
+ // 0x02, 0x2e, /* quad speed */
+ 0x03, 0x01, /* 3: de-emphasis off */
+ 0x04, 0x00, /* 4: LOUT1 volume muted */
+ 0x05, 0x00, /* 5: ROUT1 volume muted */
+ 0x06, 0x00, /* 6: LOUT2 volume muted */
+ 0x07, 0x00, /* 7: ROUT2 volume muted */
+ 0x08, 0x00, /* 8: LOUT3 volume muted */
+ 0x09, 0x00, /* 9: ROUT3 volume muted */
+ 0x0b, 0x00, /* b: LOUT4 volume muted */
+ 0x0c, 0x00, /* c: ROUT4 volume muted */
+ 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
+ 0x01, 0x01, /* 1: un-reset, unmute */
+ 0xff, 0xff
+ };
+ static unsigned char inits_ak4381[] = {
+ 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
+ 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
+ // 0x01, 0x12, /* quad speed */
+ 0x02, 0x00, /* 2: DZF disabled */
+ 0x03, 0x00, /* 3: LATT 0 */
+ 0x04, 0x00, /* 4: RATT 0 */
+ 0x00, 0x0f, /* 0: power-up, un-reset */
+ 0xff, 0xff
+ };
+
+ int chip, num_chips;
+ unsigned char *ptr, reg, data, *inits;
+
+ switch (ak->type) {
+ case SND_AK4524:
+ inits = inits_ak4524;
+ num_chips = ak->num_dacs / 2;
+ break;
+ case SND_AK4528:
+ inits = inits_ak4528;
+ num_chips = ak->num_dacs / 2;
+ break;
+ case SND_AK4529:
+ inits = inits_ak4529;
+ num_chips = 1;
+ break;
+ case SND_AK4355:
+ inits = inits_ak4355;
+ num_chips = 1;
+ break;
+ case SND_AK4358:
+ inits = inits_ak4358;
+ num_chips = 1;
+ break;
+ case SND_AK4381:
+ inits = inits_ak4381;
+ num_chips = ak->num_dacs / 2;
+ break;
+ default:
+ snd_BUG();
+ return;
+ }
+
+ for (chip = 0; chip < num_chips; chip++) {
+ ptr = inits;
+ while (*ptr != 0xff) {
+ reg = *ptr++;
+ data = *ptr++;
+ snd_akm4xxx_write(ak, chip, reg, data);
+ }
+ }
+}
+
+#define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
+#define AK_GET_ADDR(val) ((val) & 0xff)
+#define AK_GET_SHIFT(val) (((val) >> 16) & 0x7f)
+#define AK_GET_INVERT(val) (((val) >> 23) & 1)
+#define AK_GET_MASK(val) (((val) >> 24) & 0xff)
+#define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
+#define AK_INVERT (1<<23)
+
+static int snd_akm4xxx_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_akm4xxx_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ int invert = AK_GET_INVERT(kcontrol->private_value);
+ unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+ unsigned char val = snd_akm4xxx_get(ak, chip, addr);
+
+ ucontrol->value.integer.value[0] = invert ? mask - val : val;
+ return 0;
+}
+
+static int snd_akm4xxx_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ int invert = AK_GET_INVERT(kcontrol->private_value);
+ unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+ unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
+ int change;
+
+ if (invert)
+ nval = mask - nval;
+ change = snd_akm4xxx_get(ak, chip, addr) != nval;
+ if (change)
+ snd_akm4xxx_write(ak, chip, addr, nval);
+ return change;
+}
+
+static int snd_akm4xxx_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 36;
+ return 0;
+}
+
+static int snd_akm4xxx_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ ucontrol->value.integer.value[0] = snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f;
+ return 0;
+}
+
+static int snd_akm4xxx_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
+ int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval;
+ if (change)
+ snd_akm4xxx_write(ak, chip, addr, nval);
+ return change;
+}
+
+static int snd_akm4xxx_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
+{
+ static char *texts[4] = {
+ "44.1kHz", "Off", "48kHz", "32kHz",
+ };
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 1;
+ uinfo->value.enumerated.items = 4;
+ if (uinfo->value.enumerated.item >= 4)
+ uinfo->value.enumerated.item = 3;
+ strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_akm4xxx_deemphasis_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ int shift = AK_GET_SHIFT(kcontrol->private_value);
+ ucontrol->value.enumerated.item[0] = (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3;
+ return 0;
+}
+
+static int snd_akm4xxx_deemphasis_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+ akm4xxx_t *ak = snd_kcontrol_chip(kcontrol);
+ int chip = AK_GET_CHIP(kcontrol->private_value);
+ int addr = AK_GET_ADDR(kcontrol->private_value);
+ int shift = AK_GET_SHIFT(kcontrol->private_value);
+ unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
+ int change;
+
+ nval = (nval << shift) | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
+ change = snd_akm4xxx_get(ak, chip, addr) != nval;
+ if (change)
+ snd_akm4xxx_write(ak, chip, addr, nval);
+ return change;
+}
+
+/*
+ * build AK4xxx controls
+ */
+
+int snd_akm4xxx_build_controls(akm4xxx_t *ak)
+{
+ unsigned int idx, num_emphs;
+ snd_kcontrol_t *ctl;
+ int err;
+
+ ctl = kmalloc(sizeof(*ctl), GFP_KERNEL);
+ if (! ctl)
+ return -ENOMEM;
+
+ for (idx = 0; idx < ak->num_dacs; ++idx) {
+ memset(ctl, 0, sizeof(*ctl));
+ strcpy(ctl->id.name, "DAC Volume");
+ ctl->id.index = idx + ak->idx_offset * 2;
+ ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+ ctl->count = 1;
+ ctl->info = snd_akm4xxx_volume_info;
+ ctl->get = snd_akm4xxx_volume_get;
+ ctl->put = snd_akm4xxx_volume_put;
+ switch (ak->type) {
+ case SND_AK4524:
+ ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
+ break;
+ case SND_AK4528:
+ ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
+ break;
+ case SND_AK4529: {
+ int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
+ ctl->private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
+ break;
+ }
+ case SND_AK4355:
+ ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
+ break;
+ case SND_AK4358:
+ if (idx >= 6)
+ ctl->private_value = AK_COMPOSE(0, idx + 5, 0, 255); /* register 4-9, chip #0 only */
+ else
+ ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
+ break;
+ case SND_AK4381:
+ ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
+ break;
+ default:
+ err = -EINVAL;
+ goto __error;
+ }
+ ctl->private_data = ak;
+ if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
+ goto __error;
+ }
+ for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
+ memset(ctl, 0, sizeof(*ctl));
+ strcpy(ctl->id.name, "ADC Volume");
+ ctl->id.index = idx + ak->idx_offset * 2;
+ ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+ ctl->count = 1;
+ ctl->info = snd_akm4xxx_volume_info;
+ ctl->get = snd_akm4xxx_volume_get;
+ ctl->put = snd_akm4xxx_volume_put;
+ ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
+ ctl->private_data = ak;
+ if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
+ goto __error;
+
+ memset(ctl, 0, sizeof(*ctl));
+ strcpy(ctl->id.name, "IPGA Analog Capture Volume");
+ ctl->id.index = idx + ak->idx_offset * 2;
+ ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+ ctl->count = 1;
+ ctl->info = snd_akm4xxx_ipga_gain_info;
+ ctl->get = snd_akm4xxx_ipga_gain_get;
+ ctl->put = snd_akm4xxx_ipga_gain_put;
+ ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
+ ctl->private_data = ak;
+ if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
+ goto __error;
+ }
+ if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
+ num_emphs = 1;
+ else
+ num_emphs = ak->num_dacs / 2;
+ for (idx = 0; idx < num_emphs; idx++) {
+ memset(ctl, 0, sizeof(*ctl));
+ strcpy(ctl->id.name, "Deemphasis");
+ ctl->id.index = idx + ak->idx_offset;
+ ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+ ctl->count = 1;
+ ctl->info = snd_akm4xxx_deemphasis_info;
+ ctl->get = snd_akm4xxx_deemphasis_get;
+ ctl->put = snd_akm4xxx_deemphasis_put;
+ switch (ak->type) {
+ case SND_AK4524:
+ case SND_AK4528:
+ ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
+ break;
+ case SND_AK4529: {
+ int shift = idx == 3 ? 6 : (2 - idx) * 2;
+ ctl->private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
+ break;
+ }
+ case SND_AK4355:
+ case SND_AK4358:
+ ctl->private_value = AK_COMPOSE(idx, 3, 0, 0);
+ break;
+ case SND_AK4381:
+ ctl->private_value = AK_COMPOSE(idx, 1, 1, 0);
+ break;
+ }
+ ctl->private_data = ak;
+ if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
+ goto __error;
+ }
+ err = 0;
+
+ __error:
+ kfree(ctl);
+ return err;
+}
+
+static int __init alsa_akm4xxx_module_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_akm4xxx_module_exit(void)
+{
+}
+
+module_init(alsa_akm4xxx_module_init)
+module_exit(alsa_akm4xxx_module_exit)
+
+EXPORT_SYMBOL(snd_akm4xxx_write);
+EXPORT_SYMBOL(snd_akm4xxx_reset);
+EXPORT_SYMBOL(snd_akm4xxx_init);
+EXPORT_SYMBOL(snd_akm4xxx_build_controls);
diff --git a/sound/i2c/other/tea575x-tuner.c b/sound/i2c/other/tea575x-tuner.c
new file mode 100644
index 00000000000..0f05a2b9a37
--- /dev/null
+++ b/sound/i2c/other/tea575x-tuner.c
@@ -0,0 +1,233 @@
+/*
+ * ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips
+ *
+ * Copyright (c) 2004 Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * 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 <sound/driver.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <sound/core.h>
+#include <sound/tea575x-tuner.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips");
+MODULE_LICENSE("GPL");
+
+/*
+ * definitions
+ */
+
+#define TEA575X_BIT_SEARCH (1<<24) /* 1 = search action, 0 = tuned */
+#define TEA575X_BIT_UPDOWN (1<<23) /* 0 = search down, 1 = search up */
+#define TEA575X_BIT_MONO (1<<22) /* 0 = stereo, 1 = mono */
+#define TEA575X_BIT_BAND_MASK (3<<20)
+#define TEA575X_BIT_BAND_FM (0<<20)
+#define TEA575X_BIT_BAND_MW (1<<20)
+#define TEA575X_BIT_BAND_LW (1<<21)
+#define TEA575X_BIT_BAND_SW (1<<22)
+#define TEA575X_BIT_PORT_0 (1<<19) /* user bit */
+#define TEA575X_BIT_PORT_1 (1<<18) /* user bit */
+#define TEA575X_BIT_SEARCH_MASK (3<<16) /* search level */
+#define TEA575X_BIT_SEARCH_5_28 (0<<16) /* FM >5uV, AM >28uV */
+#define TEA575X_BIT_SEARCH_10_40 (1<<16) /* FM >10uV, AM > 40uV */
+#define TEA575X_BIT_SEARCH_30_63 (2<<16) /* FM >30uV, AM > 63uV */
+#define TEA575X_BIT_SEARCH_150_1000 (3<<16) /* FM > 150uV, AM > 1000uV */
+#define TEA575X_BIT_DUMMY (1<<15) /* buffer */
+#define TEA575X_BIT_FREQ_MASK 0x7fff
+
+/*
+ * lowlevel part
+ */
+
+static void snd_tea575x_set_freq(tea575x_t *tea)
+{
+ unsigned long freq;
+
+ freq = tea->freq / 16; /* to kHz */
+ if (freq > 108000)
+ freq = 108000;
+ if (freq < 87000)
+ freq = 87000;
+ /* crystal fixup */
+ if (tea->tea5759)
+ freq -= tea->freq_fixup;
+ else
+ freq += tea->freq_fixup;
+ /* freq /= 12.5 */
+ freq *= 10;
+ freq /= 125;
+
+ tea->val &= ~TEA575X_BIT_FREQ_MASK;
+ tea->val |= freq & TEA575X_BIT_FREQ_MASK;
+ tea->ops->write(tea, tea->val);
+}
+
+/*
+ * Linux Video interface
+ */
+
+static int snd_tea575x_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long data)
+{
+ struct video_device *dev = video_devdata(file);
+ tea575x_t *tea = video_get_drvdata(dev);
+ void __user *arg = (void __user *)data;
+
+ switch(cmd) {
+ case VIDIOCGCAP:
+ {
+ struct video_capability v;
+ v.type = VID_TYPE_TUNER;
+ v.channels = 1;
+ v.audios = 1;
+ /* No we don't do pictures */
+ v.maxwidth = 0;
+ v.maxheight = 0;
+ v.minwidth = 0;
+ v.minheight = 0;
+ strcpy(v.name, tea->tea5759 ? "TEA5759" : "TEA5757");
+ if (copy_to_user(arg,&v,sizeof(v)))
+ return -EFAULT;
+ return 0;
+ }
+ case VIDIOCGTUNER:
+ {
+ struct video_tuner v;
+ if (copy_from_user(&v, arg,sizeof(v))!=0)
+ return -EFAULT;
+ if (v.tuner) /* Only 1 tuner */
+ return -EINVAL;
+ v.rangelow = (87*16000);
+ v.rangehigh = (108*16000);
+ v.flags = VIDEO_TUNER_LOW;
+ v.mode = VIDEO_MODE_AUTO;
+ strcpy(v.name, "FM");
+ v.signal = 0xFFFF;
+ if (copy_to_user(arg, &v, sizeof(v)))
+ return -EFAULT;
+ return 0;
+ }
+ case VIDIOCSTUNER:
+ {
+ struct video_tuner v;
+ if(copy_from_user(&v, arg, sizeof(v)))
+ return -EFAULT;
+ if(v.tuner!=0)
+ return -EINVAL;
+ /* Only 1 tuner so no setting needed ! */
+ return 0;
+ }
+ case VIDIOCGFREQ:
+ if(copy_to_user(arg, &tea->freq, sizeof(tea->freq)))
+ return -EFAULT;
+ return 0;
+ case VIDIOCSFREQ:
+ if(copy_from_user(&tea->freq, arg, sizeof(tea->freq)))
+ return -EFAULT;
+ snd_tea575x_set_freq(tea);
+ return 0;
+ case VIDIOCGAUDIO:
+ {
+ struct video_audio v;
+ memset(&v, 0, sizeof(v));
+ strcpy(v.name, "Radio");
+ if(copy_to_user(arg,&v, sizeof(v)))
+ return -EFAULT;
+ return 0;
+ }
+ case VIDIOCSAUDIO:
+ {
+ struct video_audio v;
+ if(copy_from_user(&v, arg, sizeof(v)))
+ return -EFAULT;
+ if(v.audio)
+ return -EINVAL;
+ return 0;
+ }
+ default:
+ return -ENOIOCTLCMD;
+ }
+}
+
+static void snd_tea575x_release(struct video_device *vfd)
+{
+}
+
+/*
+ * initialize all the tea575x chips
+ */
+void snd_tea575x_init(tea575x_t *tea)
+{
+ unsigned int val;
+
+ val = tea->ops->read(tea);
+ if (val == 0x1ffffff || val == 0) {
+ snd_printk(KERN_ERR "Cannot find TEA575x chip\n");
+ return;
+ }
+
+ memset(&tea->vd, 0, sizeof(tea->vd));
+ tea->vd.owner = tea->card->module;
+ strcpy(tea->vd.name, tea->tea5759 ? "TEA5759 radio" : "TEA5757 radio");
+ tea->vd.type = VID_TYPE_TUNER;
+ tea->vd.hardware = VID_HARDWARE_RTRACK; /* FIXME: assign new number */
+ tea->vd.release = snd_tea575x_release;
+ video_set_drvdata(&tea->vd, tea);
+ tea->vd.fops = &tea->fops;
+ tea->fops.owner = tea->card->module;
+ tea->fops.open = video_exclusive_open;
+ tea->fops.release = video_exclusive_release;
+ tea->fops.ioctl = snd_tea575x_ioctl;
+ if (video_register_device(&tea->vd, VFL_TYPE_RADIO, tea->dev_nr - 1) < 0) {
+ snd_printk(KERN_ERR "unable to register tea575x tuner\n");
+ return;
+ }
+ tea->vd_registered = 1;
+
+ tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40;
+ tea->freq = 90500 * 16; /* 90.5Mhz default */
+
+ snd_tea575x_set_freq(tea);
+}
+
+void snd_tea575x_exit(tea575x_t *tea)
+{
+ if (tea->vd_registered) {
+ video_unregister_device(&tea->vd);
+ tea->vd_registered = 0;
+ }
+}
+
+static int __init alsa_tea575x_module_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_tea575x_module_exit(void)
+{
+}
+
+module_init(alsa_tea575x_module_init)
+module_exit(alsa_tea575x_module_exit)
+
+EXPORT_SYMBOL(snd_tea575x_init);
+EXPORT_SYMBOL(snd_tea575x_exit);