Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Routines for control of the AK4114 via I2C and 4-wire serial interface |
| 3 | * IEC958 (S/PDIF) receiver by Asahi Kasei |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/slab.h> |
| 24 | #include <linux/delay.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include <sound/control.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/ak4114.h> |
| 30 | #include <sound/asoundef.h> |
Pavel Hofman | fdafad6 | 2008-02-11 14:48:06 +0100 | [diff] [blame] | 31 | #include <sound/info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
| 37 | #define AK4114_ADDR 0x00 /* fixed address */ |
| 38 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 39 | static void ak4114_stats(struct work_struct *work); |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 40 | static void ak4114_init_regs(struct ak4114 *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 42 | static void reg_write(struct ak4114 *ak4114, unsigned char reg, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| 44 | ak4114->write(ak4114->private_data, reg, val); |
| 45 | if (reg <= AK4114_REG_INT1_MASK) |
| 46 | ak4114->regmap[reg] = val; |
Jean Delvare | 1ab774e | 2007-02-05 13:07:04 +0100 | [diff] [blame] | 47 | else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4) |
| 48 | ak4114->txcsb[reg-AK4114_REG_TXCSB0] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 51 | static inline unsigned char reg_read(struct ak4114 *ak4114, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | return ak4114->read(ak4114->private_data, reg); |
| 54 | } |
| 55 | |
| 56 | #if 0 |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 57 | static void reg_dump(struct ak4114 *ak4114) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | int i; |
| 60 | |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 61 | printk(KERN_DEBUG "AK4114 REG DUMP:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | for (i = 0; i < 0x20; i++) |
Takashi Iwai | e12483e | 2013-10-29 16:37:11 +0100 | [diff] [blame] | 63 | printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < ARRAY_SIZE(ak4114->regmap) ? ak4114->regmap[i] : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 67 | static void snd_ak4114_free(struct ak4114 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 69 | atomic_inc(&chip->wq_processing); /* don't schedule new work */ |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 70 | cancel_delayed_work_sync(&chip->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | kfree(chip); |
| 72 | } |
| 73 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 74 | static int snd_ak4114_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 76 | struct ak4114 *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | snd_ak4114_free(chip); |
| 78 | return 0; |
| 79 | } |
| 80 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 81 | int snd_ak4114_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | ak4114_read_t *read, ak4114_write_t *write, |
Takashi Iwai | e12483e | 2013-10-29 16:37:11 +0100 | [diff] [blame] | 83 | const unsigned char pgm[6], const unsigned char txcsb[5], |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 84 | void *private_data, struct ak4114 **r_ak4114) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 86 | struct ak4114 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | int err = 0; |
| 88 | unsigned char reg; |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 89 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | .dev_free = snd_ak4114_dev_free, |
| 91 | }; |
| 92 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 93 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (chip == NULL) |
| 95 | return -ENOMEM; |
| 96 | spin_lock_init(&chip->lock); |
| 97 | chip->card = card; |
| 98 | chip->read = read; |
| 99 | chip->write = write; |
| 100 | chip->private_data = private_data; |
Takashi Iwai | 3b6baa5 | 2007-01-31 14:34:38 +0100 | [diff] [blame] | 101 | INIT_DELAYED_WORK(&chip->work, ak4114_stats); |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 102 | atomic_set(&chip->wq_processing, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Takashi Iwai | e12483e | 2013-10-29 16:37:11 +0100 | [diff] [blame] | 104 | for (reg = 0; reg < 6; reg++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | chip->regmap[reg] = pgm[reg]; |
| 106 | for (reg = 0; reg < 5; reg++) |
| 107 | chip->txcsb[reg] = txcsb[reg]; |
| 108 | |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 109 | ak4114_init_regs(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); |
| 112 | chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); |
| 113 | |
Takashi Iwai | 483eb06 | 2014-02-04 11:18:23 +0100 | [diff] [blame] | 114 | if ((err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | goto __fail; |
| 116 | |
| 117 | if (r_ak4114) |
| 118 | *r_ak4114 = chip; |
| 119 | return 0; |
| 120 | |
| 121 | __fail: |
| 122 | snd_ak4114_free(chip); |
| 123 | return err < 0 ? err : -EIO; |
| 124 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 125 | EXPORT_SYMBOL(snd_ak4114_create); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 127 | void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned char mask, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | if (reg <= AK4114_REG_INT1_MASK) |
| 130 | reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); |
| 131 | else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4) |
Jean Delvare | 1ab774e | 2007-02-05 13:07:04 +0100 | [diff] [blame] | 132 | reg_write(chip, reg, |
| 133 | (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 135 | EXPORT_SYMBOL(snd_ak4114_reg_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 137 | static void ak4114_init_regs(struct ak4114 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
| 139 | unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* bring the chip to reset state and powerdown state */ |
| 142 | reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); |
| 143 | udelay(200); |
| 144 | /* release reset, but leave powerdown */ |
| 145 | reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); |
| 146 | udelay(200); |
Takashi Iwai | e12483e | 2013-10-29 16:37:11 +0100 | [diff] [blame] | 147 | for (reg = 1; reg < 6; reg++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | reg_write(chip, reg, chip->regmap[reg]); |
| 149 | for (reg = 0; reg < 5; reg++) |
| 150 | reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); |
| 151 | /* release powerdown, everything is initialized now */ |
| 152 | reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void snd_ak4114_reinit(struct ak4114 *chip) |
| 156 | { |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 157 | if (atomic_inc_return(&chip->wq_processing) == 1) |
| 158 | cancel_delayed_work_sync(&chip->work); |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 159 | ak4114_init_regs(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* bring up statistics / event queing */ |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 161 | if (atomic_dec_and_test(&chip->wq_processing)) |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 162 | schedule_delayed_work(&chip->work, HZ / 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 164 | EXPORT_SYMBOL(snd_ak4114_reinit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | static unsigned int external_rate(unsigned char rcs1) |
| 167 | { |
| 168 | switch (rcs1 & (AK4114_FS0|AK4114_FS1|AK4114_FS2|AK4114_FS3)) { |
| 169 | case AK4114_FS_32000HZ: return 32000; |
| 170 | case AK4114_FS_44100HZ: return 44100; |
| 171 | case AK4114_FS_48000HZ: return 48000; |
| 172 | case AK4114_FS_88200HZ: return 88200; |
| 173 | case AK4114_FS_96000HZ: return 96000; |
| 174 | case AK4114_FS_176400HZ: return 176400; |
| 175 | case AK4114_FS_192000HZ: return 192000; |
| 176 | default: return 0; |
| 177 | } |
| 178 | } |
| 179 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 180 | static int snd_ak4114_in_error_info(struct snd_kcontrol *kcontrol, |
| 181 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
| 183 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 184 | uinfo->count = 1; |
| 185 | uinfo->value.integer.min = 0; |
| 186 | uinfo->value.integer.max = LONG_MAX; |
| 187 | return 0; |
| 188 | } |
| 189 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 190 | static int snd_ak4114_in_error_get(struct snd_kcontrol *kcontrol, |
| 191 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 193 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | long *ptr; |
| 195 | |
| 196 | spin_lock_irq(&chip->lock); |
| 197 | ptr = (long *)(((char *)chip) + kcontrol->private_value); |
| 198 | ucontrol->value.integer.value[0] = *ptr; |
| 199 | *ptr = 0; |
| 200 | spin_unlock_irq(&chip->lock); |
| 201 | return 0; |
| 202 | } |
| 203 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 204 | #define snd_ak4114_in_bit_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 206 | static int snd_ak4114_in_bit_get(struct snd_kcontrol *kcontrol, |
| 207 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 209 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | unsigned char reg = kcontrol->private_value & 0xff; |
| 211 | unsigned char bit = (kcontrol->private_value >> 8) & 0xff; |
| 212 | unsigned char inv = (kcontrol->private_value >> 31) & 1; |
| 213 | |
| 214 | ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; |
| 215 | return 0; |
| 216 | } |
| 217 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 218 | static int snd_ak4114_rate_info(struct snd_kcontrol *kcontrol, |
| 219 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 222 | uinfo->count = 1; |
| 223 | uinfo->value.integer.min = 0; |
| 224 | uinfo->value.integer.max = 192000; |
| 225 | return 0; |
| 226 | } |
| 227 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 228 | static int snd_ak4114_rate_get(struct snd_kcontrol *kcontrol, |
| 229 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 231 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1)); |
| 234 | return 0; |
| 235 | } |
| 236 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 237 | static int snd_ak4114_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 240 | uinfo->count = 1; |
| 241 | return 0; |
| 242 | } |
| 243 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 244 | static int snd_ak4114_spdif_get(struct snd_kcontrol *kcontrol, |
| 245 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 247 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | unsigned i; |
| 249 | |
| 250 | for (i = 0; i < AK4114_REG_RXCSB_SIZE; i++) |
| 251 | ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i); |
| 252 | return 0; |
| 253 | } |
| 254 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 255 | static int snd_ak4114_spdif_playback_get(struct snd_kcontrol *kcontrol, |
| 256 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 258 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | unsigned i; |
| 260 | |
| 261 | for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) |
| 262 | ucontrol->value.iec958.status[i] = chip->txcsb[i]; |
| 263 | return 0; |
| 264 | } |
| 265 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 266 | static int snd_ak4114_spdif_playback_put(struct snd_kcontrol *kcontrol, |
| 267 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 269 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | unsigned i; |
| 271 | |
| 272 | for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) |
| 273 | reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]); |
| 274 | return 0; |
| 275 | } |
| 276 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 277 | static int snd_ak4114_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
| 279 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 280 | uinfo->count = 1; |
| 281 | return 0; |
| 282 | } |
| 283 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 284 | static int snd_ak4114_spdif_mask_get(struct snd_kcontrol *kcontrol, |
| 285 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE); |
| 288 | return 0; |
| 289 | } |
| 290 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 291 | static int snd_ak4114_spdif_pinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 294 | uinfo->value.integer.min = 0; |
| 295 | uinfo->value.integer.max = 0xffff; |
| 296 | uinfo->count = 4; |
| 297 | return 0; |
| 298 | } |
| 299 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 300 | static int snd_ak4114_spdif_pget(struct snd_kcontrol *kcontrol, |
| 301 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 303 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | unsigned short tmp; |
| 305 | |
| 306 | ucontrol->value.integer.value[0] = 0xf8f2; |
| 307 | ucontrol->value.integer.value[1] = 0x4e1f; |
| 308 | tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8); |
| 309 | ucontrol->value.integer.value[2] = tmp; |
| 310 | tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8); |
| 311 | ucontrol->value.integer.value[3] = tmp; |
| 312 | return 0; |
| 313 | } |
| 314 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 315 | static int snd_ak4114_spdif_qinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
| 317 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 318 | uinfo->count = AK4114_REG_QSUB_SIZE; |
| 319 | return 0; |
| 320 | } |
| 321 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 322 | static int snd_ak4114_spdif_qget(struct snd_kcontrol *kcontrol, |
| 323 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 325 | struct ak4114 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | unsigned i; |
| 327 | |
| 328 | for (i = 0; i < AK4114_REG_QSUB_SIZE; i++) |
| 329 | ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* Don't forget to change AK4114_CONTROLS define!!! */ |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 334 | static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 337 | .name = "IEC958 Parity Errors", |
| 338 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 339 | .info = snd_ak4114_in_error_info, |
| 340 | .get = snd_ak4114_in_error_get, |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 341 | .private_value = offsetof(struct ak4114, parity_errors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | }, |
| 343 | { |
| 344 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 345 | .name = "IEC958 V-Bit Errors", |
| 346 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 347 | .info = snd_ak4114_in_error_info, |
| 348 | .get = snd_ak4114_in_error_get, |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 349 | .private_value = offsetof(struct ak4114, v_bit_errors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | }, |
| 351 | { |
| 352 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 353 | .name = "IEC958 C-CRC Errors", |
| 354 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 355 | .info = snd_ak4114_in_error_info, |
| 356 | .get = snd_ak4114_in_error_get, |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 357 | .private_value = offsetof(struct ak4114, ccrc_errors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | }, |
| 359 | { |
| 360 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 361 | .name = "IEC958 Q-CRC Errors", |
| 362 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 363 | .info = snd_ak4114_in_error_info, |
| 364 | .get = snd_ak4114_in_error_get, |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 365 | .private_value = offsetof(struct ak4114, qcrc_errors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | }, |
| 367 | { |
| 368 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 369 | .name = "IEC958 External Rate", |
| 370 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 371 | .info = snd_ak4114_rate_info, |
| 372 | .get = snd_ak4114_rate_get, |
| 373 | }, |
| 374 | { |
| 375 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 376 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 377 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 378 | .info = snd_ak4114_spdif_mask_info, |
| 379 | .get = snd_ak4114_spdif_mask_get, |
| 380 | }, |
| 381 | { |
| 382 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 383 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 384 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 385 | .info = snd_ak4114_spdif_info, |
| 386 | .get = snd_ak4114_spdif_playback_get, |
| 387 | .put = snd_ak4114_spdif_playback_put, |
| 388 | }, |
| 389 | { |
| 390 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 391 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), |
| 392 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 393 | .info = snd_ak4114_spdif_mask_info, |
| 394 | .get = snd_ak4114_spdif_mask_get, |
| 395 | }, |
| 396 | { |
| 397 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 398 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), |
| 399 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 400 | .info = snd_ak4114_spdif_info, |
| 401 | .get = snd_ak4114_spdif_get, |
| 402 | }, |
| 403 | { |
| 404 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Masanari Iida | ec8f53f | 2012-11-02 00:28:50 +0900 | [diff] [blame] | 405 | .name = "IEC958 Preamble Capture Default", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 407 | .info = snd_ak4114_spdif_pinfo, |
| 408 | .get = snd_ak4114_spdif_pget, |
| 409 | }, |
| 410 | { |
| 411 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 412 | .name = "IEC958 Q-subcode Capture Default", |
| 413 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 414 | .info = snd_ak4114_spdif_qinfo, |
| 415 | .get = snd_ak4114_spdif_qget, |
| 416 | }, |
| 417 | { |
| 418 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 419 | .name = "IEC958 Audio", |
| 420 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 421 | .info = snd_ak4114_in_bit_info, |
| 422 | .get = snd_ak4114_in_bit_get, |
| 423 | .private_value = (1<<31) | (1<<8) | AK4114_REG_RCS0, |
| 424 | }, |
| 425 | { |
| 426 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 427 | .name = "IEC958 Non-PCM Bitstream", |
| 428 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 429 | .info = snd_ak4114_in_bit_info, |
| 430 | .get = snd_ak4114_in_bit_get, |
Pavel Hofman | c4116ae | 2007-04-05 17:07:30 +0200 | [diff] [blame] | 431 | .private_value = (6<<8) | AK4114_REG_RCS0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | }, |
| 433 | { |
| 434 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 435 | .name = "IEC958 DTS Bitstream", |
| 436 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 437 | .info = snd_ak4114_in_bit_info, |
| 438 | .get = snd_ak4114_in_bit_get, |
Pavel Hofman | c4116ae | 2007-04-05 17:07:30 +0200 | [diff] [blame] | 439 | .private_value = (3<<8) | AK4114_REG_RCS0, |
| 440 | }, |
| 441 | { |
| 442 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 443 | .name = "IEC958 PPL Lock Status", |
| 444 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 445 | .info = snd_ak4114_in_bit_info, |
| 446 | .get = snd_ak4114_in_bit_get, |
| 447 | .private_value = (1<<31) | (4<<8) | AK4114_REG_RCS0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | }; |
| 450 | |
Pavel Hofman | fdafad6 | 2008-02-11 14:48:06 +0100 | [diff] [blame] | 451 | |
| 452 | static void snd_ak4114_proc_regs_read(struct snd_info_entry *entry, |
| 453 | struct snd_info_buffer *buffer) |
| 454 | { |
| 455 | struct ak4114 *ak4114 = entry->private_data; |
| 456 | int reg, val; |
| 457 | /* all ak4114 registers 0x00 - 0x1f */ |
| 458 | for (reg = 0; reg < 0x20; reg++) { |
| 459 | val = reg_read(ak4114, reg); |
| 460 | snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | static void snd_ak4114_proc_init(struct ak4114 *ak4114) |
| 465 | { |
| 466 | struct snd_info_entry *entry; |
| 467 | if (!snd_card_proc_new(ak4114->card, "ak4114", &entry)) |
| 468 | snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read); |
| 469 | } |
| 470 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 471 | int snd_ak4114_build(struct ak4114 *ak4114, |
| 472 | struct snd_pcm_substream *ply_substream, |
| 473 | struct snd_pcm_substream *cap_substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 475 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | unsigned int idx; |
| 477 | int err; |
| 478 | |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 479 | if (snd_BUG_ON(!cap_substream)) |
| 480 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | ak4114->playback_substream = ply_substream; |
| 482 | ak4114->capture_substream = cap_substream; |
| 483 | for (idx = 0; idx < AK4114_CONTROLS; idx++) { |
| 484 | kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114); |
| 485 | if (kctl == NULL) |
| 486 | return -ENOMEM; |
Pavel Hofman | c4116ae | 2007-04-05 17:07:30 +0200 | [diff] [blame] | 487 | if (strstr(kctl->id.name, "Playback")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | if (ply_substream == NULL) { |
| 489 | snd_ctl_free_one(kctl); |
| 490 | ak4114->kctls[idx] = NULL; |
| 491 | continue; |
| 492 | } |
| 493 | kctl->id.device = ply_substream->pcm->device; |
| 494 | kctl->id.subdevice = ply_substream->number; |
| 495 | } else { |
| 496 | kctl->id.device = cap_substream->pcm->device; |
| 497 | kctl->id.subdevice = cap_substream->number; |
| 498 | } |
| 499 | err = snd_ctl_add(ak4114->card, kctl); |
| 500 | if (err < 0) |
| 501 | return err; |
| 502 | ak4114->kctls[idx] = kctl; |
| 503 | } |
Pavel Hofman | fdafad6 | 2008-02-11 14:48:06 +0100 | [diff] [blame] | 504 | snd_ak4114_proc_init(ak4114); |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 505 | /* trigger workq */ |
| 506 | schedule_delayed_work(&ak4114->work, HZ / 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return 0; |
| 508 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 509 | EXPORT_SYMBOL(snd_ak4114_build); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 511 | /* notify kcontrols if any parameters are changed */ |
| 512 | static void ak4114_notify(struct ak4114 *ak4114, |
| 513 | unsigned char rcs0, unsigned char rcs1, |
| 514 | unsigned char c0, unsigned char c1) |
| 515 | { |
| 516 | if (!ak4114->kctls[0]) |
| 517 | return; |
| 518 | |
| 519 | if (rcs0 & AK4114_PAR) |
| 520 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 521 | &ak4114->kctls[0]->id); |
| 522 | if (rcs0 & AK4114_V) |
| 523 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 524 | &ak4114->kctls[1]->id); |
| 525 | if (rcs1 & AK4114_CCRC) |
| 526 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 527 | &ak4114->kctls[2]->id); |
| 528 | if (rcs1 & AK4114_QCRC) |
| 529 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 530 | &ak4114->kctls[3]->id); |
| 531 | |
| 532 | /* rate change */ |
| 533 | if (c1 & 0xf0) |
| 534 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 535 | &ak4114->kctls[4]->id); |
| 536 | |
| 537 | if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT)) |
| 538 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 539 | &ak4114->kctls[9]->id); |
| 540 | if (c0 & AK4114_QINT) |
| 541 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 542 | &ak4114->kctls[10]->id); |
| 543 | |
| 544 | if (c0 & AK4114_AUDION) |
| 545 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 546 | &ak4114->kctls[11]->id); |
| 547 | if (c0 & AK4114_AUTO) |
| 548 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 549 | &ak4114->kctls[12]->id); |
| 550 | if (c0 & AK4114_DTSCD) |
| 551 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 552 | &ak4114->kctls[13]->id); |
Pavel Hofman | c4116ae | 2007-04-05 17:07:30 +0200 | [diff] [blame] | 553 | if (c0 & AK4114_UNLCK) |
| 554 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 555 | &ak4114->kctls[14]->id); |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 556 | } |
| 557 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 558 | int snd_ak4114_external_rate(struct ak4114 *ak4114) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
| 560 | unsigned char rcs1; |
| 561 | |
| 562 | rcs1 = reg_read(ak4114, AK4114_REG_RCS1); |
| 563 | return external_rate(rcs1); |
| 564 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 565 | EXPORT_SYMBOL(snd_ak4114_external_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 567 | int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 569 | struct snd_pcm_runtime *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | unsigned long _flags; |
| 571 | int res = 0; |
| 572 | unsigned char rcs0, rcs1; |
| 573 | unsigned char c0, c1; |
| 574 | |
| 575 | rcs1 = reg_read(ak4114, AK4114_REG_RCS1); |
| 576 | if (flags & AK4114_CHECK_NO_STAT) |
| 577 | goto __rate; |
| 578 | rcs0 = reg_read(ak4114, AK4114_REG_RCS0); |
| 579 | spin_lock_irqsave(&ak4114->lock, _flags); |
| 580 | if (rcs0 & AK4114_PAR) |
| 581 | ak4114->parity_errors++; |
| 582 | if (rcs1 & AK4114_V) |
| 583 | ak4114->v_bit_errors++; |
| 584 | if (rcs1 & AK4114_CCRC) |
| 585 | ak4114->ccrc_errors++; |
| 586 | if (rcs1 & AK4114_QCRC) |
| 587 | ak4114->qcrc_errors++; |
| 588 | c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^ |
| 589 | (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)); |
| 590 | c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); |
| 591 | ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT); |
| 592 | ak4114->rcs1 = rcs1; |
| 593 | spin_unlock_irqrestore(&ak4114->lock, _flags); |
| 594 | |
Takashi Iwai | 51354ae | 2007-03-30 15:38:39 +0200 | [diff] [blame] | 595 | ak4114_notify(ak4114, rcs0, rcs1, c0, c1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | if (ak4114->change_callback && (c0 | c1) != 0) |
| 597 | ak4114->change_callback(ak4114, c0, c1); |
| 598 | |
| 599 | __rate: |
| 600 | /* compare rate */ |
| 601 | res = external_rate(rcs1); |
| 602 | if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { |
| 603 | snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); |
| 604 | if (snd_pcm_running(ak4114->capture_substream)) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 605 | // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | res = 1; |
| 608 | } |
| 609 | snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags); |
| 610 | } |
| 611 | return res; |
| 612 | } |
Takashi Iwai | a850ef8 | 2015-01-13 10:58:31 +0100 | [diff] [blame] | 613 | EXPORT_SYMBOL(snd_ak4114_check_rate_and_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 615 | static void ak4114_stats(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 617 | struct ak4114 *chip = container_of(work, struct ak4114, work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 619 | if (atomic_inc_return(&chip->wq_processing) == 1) |
Pavel Hofman | 841b23d | 2008-03-17 08:45:33 +0100 | [diff] [blame] | 620 | snd_ak4114_check_rate_and_errors(chip, chip->check_flags); |
Takashi Iwai | 4161b45 | 2015-01-13 10:53:20 +0100 | [diff] [blame] | 621 | if (atomic_dec_and_test(&chip->wq_processing)) |
| 622 | schedule_delayed_work(&chip->work, HZ / 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
Takashi Iwai | 1293617 | 2015-01-13 11:24:08 +0100 | [diff] [blame^] | 624 | |
| 625 | #ifdef CONFIG_PM |
| 626 | void snd_ak4114_suspend(struct ak4114 *chip) |
| 627 | { |
| 628 | atomic_inc(&chip->wq_processing); /* don't schedule new work */ |
| 629 | cancel_delayed_work_sync(&chip->work); |
| 630 | } |
| 631 | EXPORT_SYMBOL(snd_ak4114_suspend); |
| 632 | |
| 633 | void snd_ak4114_resume(struct ak4114 *chip) |
| 634 | { |
| 635 | atomic_dec(&chip->wq_processing); |
| 636 | snd_ak4114_reinit(chip); |
| 637 | } |
| 638 | EXPORT_SYMBOL(snd_ak4114_resume); |
| 639 | #endif |