~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/i2c/other/ak4113.c

Version: ~ [ linux-5.6-rc1 ] ~ [ linux-5.5.2 ] ~ [ linux-5.4.17 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.102 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.170 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.213 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.213 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/i2c/other/ak4113.c (Architecture i386) and /sound/i2c/other/ak4113.c (Architecture m68k)


  1 /*                                                  1 /*
  2  *  Routines for control of the AK4113 via I2C      2  *  Routines for control of the AK4113 via I2C/4-wire serial interface
  3  *  IEC958 (S/PDIF) receiver by Asahi Kasei         3  *  IEC958 (S/PDIF) receiver by Asahi Kasei
  4  *  Copyright (c) by Jaroslav Kysela <perex@pe      4  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  5  *  Copyright (c) by Pavel Hofman <pavel.hofma      5  *  Copyright (c) by Pavel Hofman <pavel.hofman@ivitera.com>
  6  *                                                  6  *
  7  *                                                  7  *
  8  *   This program is free software; you can re      8  *   This program is free software; you can redistribute it and/or modify
  9  *   it under the terms of the GNU General Pub      9  *   it under the terms of the GNU General Public License as published by
 10  *   the Free Software Foundation; either vers     10  *   the Free Software Foundation; either version 2 of the License, or
 11  *   (at your option) any later version.           11  *   (at your option) any later version.
 12  *                                                 12  *
 13  *   This program is distributed in the hope t     13  *   This program is distributed in the hope that it will be useful,
 14  *   but WITHOUT ANY WARRANTY; without even th     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  *   MERCHANTABILITY or FITNESS FOR A PARTICUL     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  *   GNU General Public License for more detai     16  *   GNU General Public License for more details.
 17  *                                                 17  *
 18  *   You should have received a copy of the GN     18  *   You should have received a copy of the GNU General Public License
 19  *   along with this program; if not, write to     19  *   along with this program; if not, write to the Free Software
 20  *   Foundation, Inc., 59 Temple Place, Suite      20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 21  *                                                 21  *
 22  */                                                22  */
 23                                                    23 
 24 #include <linux/slab.h>                            24 #include <linux/slab.h>
 25 #include <linux/delay.h>                           25 #include <linux/delay.h>
 26 #include <linux/module.h>                          26 #include <linux/module.h>
 27 #include <sound/core.h>                            27 #include <sound/core.h>
 28 #include <sound/control.h>                         28 #include <sound/control.h>
 29 #include <sound/pcm.h>                             29 #include <sound/pcm.h>
 30 #include <sound/ak4113.h>                          30 #include <sound/ak4113.h>
 31 #include <sound/asoundef.h>                        31 #include <sound/asoundef.h>
 32 #include <sound/info.h>                            32 #include <sound/info.h>
 33                                                    33 
 34 MODULE_AUTHOR("Pavel Hofman <pavel.hofman@ivit     34 MODULE_AUTHOR("Pavel Hofman <pavel.hofman@ivitera.com>");
 35 MODULE_DESCRIPTION("AK4113 IEC958 (S/PDIF) rec     35 MODULE_DESCRIPTION("AK4113 IEC958 (S/PDIF) receiver by Asahi Kasei");
 36 MODULE_LICENSE("GPL");                             36 MODULE_LICENSE("GPL");
 37                                                    37 
 38 #define AK4113_ADDR                     0x00 /     38 #define AK4113_ADDR                     0x00 /* fixed address */
 39                                                    39 
 40 static void ak4113_stats(struct work_struct *w     40 static void ak4113_stats(struct work_struct *work);
 41 static void ak4113_init_regs(struct ak4113 *ch     41 static void ak4113_init_regs(struct ak4113 *chip);
 42                                                    42 
 43                                                    43 
 44 static void reg_write(struct ak4113 *ak4113, u     44 static void reg_write(struct ak4113 *ak4113, unsigned char reg,
 45                 unsigned char val)                 45                 unsigned char val)
 46 {                                                  46 {
 47         ak4113->write(ak4113->private_data, re     47         ak4113->write(ak4113->private_data, reg, val);
 48         if (reg < sizeof(ak4113->regmap))          48         if (reg < sizeof(ak4113->regmap))
 49                 ak4113->regmap[reg] = val;         49                 ak4113->regmap[reg] = val;
 50 }                                                  50 }
 51                                                    51 
 52 static inline unsigned char reg_read(struct ak     52 static inline unsigned char reg_read(struct ak4113 *ak4113, unsigned char reg)
 53 {                                                  53 {
 54         return ak4113->read(ak4113->private_da     54         return ak4113->read(ak4113->private_data, reg);
 55 }                                                  55 }
 56                                                    56 
 57 static void snd_ak4113_free(struct ak4113 *chi     57 static void snd_ak4113_free(struct ak4113 *chip)
 58 {                                                  58 {
 59         atomic_inc(&chip->wq_processing);          59         atomic_inc(&chip->wq_processing);       /* don't schedule new work */
 60         cancel_delayed_work_sync(&chip->work);     60         cancel_delayed_work_sync(&chip->work);
 61         kfree(chip);                               61         kfree(chip);
 62 }                                                  62 }
 63                                                    63 
 64 static int snd_ak4113_dev_free(struct snd_devi     64 static int snd_ak4113_dev_free(struct snd_device *device)
 65 {                                                  65 {
 66         struct ak4113 *chip = device->device_d     66         struct ak4113 *chip = device->device_data;
 67         snd_ak4113_free(chip);                     67         snd_ak4113_free(chip);
 68         return 0;                                  68         return 0;
 69 }                                                  69 }
 70                                                    70 
 71 int snd_ak4113_create(struct snd_card *card, a     71 int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
 72                 ak4113_write_t *write, const u     72                 ak4113_write_t *write, const unsigned char *pgm,
 73                 void *private_data, struct ak4     73                 void *private_data, struct ak4113 **r_ak4113)
 74 {                                                  74 {
 75         struct ak4113 *chip;                       75         struct ak4113 *chip;
 76         int err;                                   76         int err;
 77         unsigned char reg;                         77         unsigned char reg;
 78         static struct snd_device_ops ops = {       78         static struct snd_device_ops ops = {
 79                 .dev_free =     snd_ak4113_dev     79                 .dev_free =     snd_ak4113_dev_free,
 80         };                                         80         };
 81                                                    81 
 82         chip = kzalloc(sizeof(*chip), GFP_KERN     82         chip = kzalloc(sizeof(*chip), GFP_KERNEL);
 83         if (chip == NULL)                          83         if (chip == NULL)
 84                 return -ENOMEM;                    84                 return -ENOMEM;
 85         spin_lock_init(&chip->lock);               85         spin_lock_init(&chip->lock);
 86         chip->card = card;                         86         chip->card = card;
 87         chip->read = read;                         87         chip->read = read;
 88         chip->write = write;                       88         chip->write = write;
 89         chip->private_data = private_data;         89         chip->private_data = private_data;
 90         INIT_DELAYED_WORK(&chip->work, ak4113_     90         INIT_DELAYED_WORK(&chip->work, ak4113_stats);
 91         atomic_set(&chip->wq_processing, 0);       91         atomic_set(&chip->wq_processing, 0);
 92         mutex_init(&chip->reinit_mutex);           92         mutex_init(&chip->reinit_mutex);
 93                                                    93 
 94         for (reg = 0; reg < AK4113_WRITABLE_RE     94         for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
 95                 chip->regmap[reg] = pgm[reg];      95                 chip->regmap[reg] = pgm[reg];
 96         ak4113_init_regs(chip);                    96         ak4113_init_regs(chip);
 97                                                    97 
 98         chip->rcs0 = reg_read(chip, AK4113_REG     98         chip->rcs0 = reg_read(chip, AK4113_REG_RCS0) & ~(AK4113_QINT |
 99                         AK4113_CINT | AK4113_S     99                         AK4113_CINT | AK4113_STC);
100         chip->rcs1 = reg_read(chip, AK4113_REG    100         chip->rcs1 = reg_read(chip, AK4113_REG_RCS1);
101         chip->rcs2 = reg_read(chip, AK4113_REG    101         chip->rcs2 = reg_read(chip, AK4113_REG_RCS2);
102         err = snd_device_new(card, SNDRV_DEV_C    102         err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops);
103         if (err < 0)                              103         if (err < 0)
104                 goto __fail;                      104                 goto __fail;
105                                                   105 
106         if (r_ak4113)                             106         if (r_ak4113)
107                 *r_ak4113 = chip;                 107                 *r_ak4113 = chip;
108         return 0;                                 108         return 0;
109                                                   109 
110 __fail:                                           110 __fail:
111         snd_ak4113_free(chip);                    111         snd_ak4113_free(chip);
112         return err;                               112         return err;
113 }                                                 113 }
114 EXPORT_SYMBOL_GPL(snd_ak4113_create);             114 EXPORT_SYMBOL_GPL(snd_ak4113_create);
115                                                   115 
116 void snd_ak4113_reg_write(struct ak4113 *chip,    116 void snd_ak4113_reg_write(struct ak4113 *chip, unsigned char reg,
117                 unsigned char mask, unsigned c    117                 unsigned char mask, unsigned char val)
118 {                                                 118 {
119         if (reg >= AK4113_WRITABLE_REGS)          119         if (reg >= AK4113_WRITABLE_REGS)
120                 return;                           120                 return;
121         reg_write(chip, reg, (chip->regmap[reg    121         reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
122 }                                                 122 }
123 EXPORT_SYMBOL_GPL(snd_ak4113_reg_write);          123 EXPORT_SYMBOL_GPL(snd_ak4113_reg_write);
124                                                   124 
125 static void ak4113_init_regs(struct ak4113 *ch    125 static void ak4113_init_regs(struct ak4113 *chip)
126 {                                                 126 {
127         unsigned char old = chip->regmap[AK411    127         unsigned char old = chip->regmap[AK4113_REG_PWRDN], reg;
128                                                   128 
129         /* bring the chip to reset state and p    129         /* bring the chip to reset state and powerdown state */
130         reg_write(chip, AK4113_REG_PWRDN, old     130         reg_write(chip, AK4113_REG_PWRDN, old & ~(AK4113_RST|AK4113_PWN));
131         udelay(200);                              131         udelay(200);
132         /* release reset, but leave powerdown     132         /* release reset, but leave powerdown */
133         reg_write(chip, AK4113_REG_PWRDN, (old    133         reg_write(chip, AK4113_REG_PWRDN, (old | AK4113_RST) & ~AK4113_PWN);
134         udelay(200);                              134         udelay(200);
135         for (reg = 1; reg < AK4113_WRITABLE_RE    135         for (reg = 1; reg < AK4113_WRITABLE_REGS; reg++)
136                 reg_write(chip, reg, chip->reg    136                 reg_write(chip, reg, chip->regmap[reg]);
137         /* release powerdown, everything is in    137         /* release powerdown, everything is initialized now */
138         reg_write(chip, AK4113_REG_PWRDN, old     138         reg_write(chip, AK4113_REG_PWRDN, old | AK4113_RST | AK4113_PWN);
139 }                                                 139 }
140                                                   140 
141 void snd_ak4113_reinit(struct ak4113 *chip)       141 void snd_ak4113_reinit(struct ak4113 *chip)
142 {                                                 142 {
143         if (atomic_inc_return(&chip->wq_proces    143         if (atomic_inc_return(&chip->wq_processing) == 1)
144                 cancel_delayed_work_sync(&chip    144                 cancel_delayed_work_sync(&chip->work);
145         mutex_lock(&chip->reinit_mutex);          145         mutex_lock(&chip->reinit_mutex);
146         ak4113_init_regs(chip);                   146         ak4113_init_regs(chip);
147         mutex_unlock(&chip->reinit_mutex);        147         mutex_unlock(&chip->reinit_mutex);
148         /* bring up statistics / event queing     148         /* bring up statistics / event queing */
149         if (atomic_dec_and_test(&chip->wq_proc    149         if (atomic_dec_and_test(&chip->wq_processing))
150                 schedule_delayed_work(&chip->w    150                 schedule_delayed_work(&chip->work, HZ / 10);
151 }                                                 151 }
152 EXPORT_SYMBOL_GPL(snd_ak4113_reinit);             152 EXPORT_SYMBOL_GPL(snd_ak4113_reinit);
153                                                   153 
154 static unsigned int external_rate(unsigned cha    154 static unsigned int external_rate(unsigned char rcs1)
155 {                                                 155 {
156         switch (rcs1 & (AK4113_FS0|AK4113_FS1|    156         switch (rcs1 & (AK4113_FS0|AK4113_FS1|AK4113_FS2|AK4113_FS3)) {
157         case AK4113_FS_8000HZ:                    157         case AK4113_FS_8000HZ:
158                 return 8000;                      158                 return 8000;
159         case AK4113_FS_11025HZ:                   159         case AK4113_FS_11025HZ:
160                 return 11025;                     160                 return 11025;
161         case AK4113_FS_16000HZ:                   161         case AK4113_FS_16000HZ:
162                 return 16000;                     162                 return 16000;
163         case AK4113_FS_22050HZ:                   163         case AK4113_FS_22050HZ:
164                 return 22050;                     164                 return 22050;
165         case AK4113_FS_24000HZ:                   165         case AK4113_FS_24000HZ:
166                 return 24000;                     166                 return 24000;
167         case AK4113_FS_32000HZ:                   167         case AK4113_FS_32000HZ:
168                 return 32000;                     168                 return 32000;
169         case AK4113_FS_44100HZ:                   169         case AK4113_FS_44100HZ:
170                 return 44100;                     170                 return 44100;
171         case AK4113_FS_48000HZ:                   171         case AK4113_FS_48000HZ:
172                 return 48000;                     172                 return 48000;
173         case AK4113_FS_64000HZ:                   173         case AK4113_FS_64000HZ:
174                 return 64000;                     174                 return 64000;
175         case AK4113_FS_88200HZ:                   175         case AK4113_FS_88200HZ:
176                 return 88200;                     176                 return 88200;
177         case AK4113_FS_96000HZ:                   177         case AK4113_FS_96000HZ:
178                 return 96000;                     178                 return 96000;
179         case AK4113_FS_176400HZ:                  179         case AK4113_FS_176400HZ:
180                 return 176400;                    180                 return 176400;
181         case AK4113_FS_192000HZ:                  181         case AK4113_FS_192000HZ:
182                 return 192000;                    182                 return 192000;
183         default:                                  183         default:
184                 return 0;                         184                 return 0;
185         }                                         185         }
186 }                                                 186 }
187                                                   187 
188 static int snd_ak4113_in_error_info(struct snd    188 static int snd_ak4113_in_error_info(struct snd_kcontrol *kcontrol,
189                                     struct snd    189                                     struct snd_ctl_elem_info *uinfo)
190 {                                                 190 {
191         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    191         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
192         uinfo->count = 1;                         192         uinfo->count = 1;
193         uinfo->value.integer.min = 0;             193         uinfo->value.integer.min = 0;
194         uinfo->value.integer.max = LONG_MAX;      194         uinfo->value.integer.max = LONG_MAX;
195         return 0;                                 195         return 0;
196 }                                                 196 }
197                                                   197 
198 static int snd_ak4113_in_error_get(struct snd_    198 static int snd_ak4113_in_error_get(struct snd_kcontrol *kcontrol,
199                                    struct snd_    199                                    struct snd_ctl_elem_value *ucontrol)
200 {                                                 200 {
201         struct ak4113 *chip = snd_kcontrol_chi    201         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
202         long *ptr;                                202         long *ptr;
203                                                   203 
204         spin_lock_irq(&chip->lock);               204         spin_lock_irq(&chip->lock);
205         ptr = (long *)(((char *)chip) + kcontr    205         ptr = (long *)(((char *)chip) + kcontrol->private_value);
206         ucontrol->value.integer.value[0] = *pt    206         ucontrol->value.integer.value[0] = *ptr;
207         *ptr = 0;                                 207         *ptr = 0;
208         spin_unlock_irq(&chip->lock);             208         spin_unlock_irq(&chip->lock);
209         return 0;                                 209         return 0;
210 }                                                 210 }
211                                                   211 
212 #define snd_ak4113_in_bit_info          snd_ct    212 #define snd_ak4113_in_bit_info          snd_ctl_boolean_mono_info
213                                                   213 
214 static int snd_ak4113_in_bit_get(struct snd_kc    214 static int snd_ak4113_in_bit_get(struct snd_kcontrol *kcontrol,
215                                  struct snd_ct    215                                  struct snd_ctl_elem_value *ucontrol)
216 {                                                 216 {
217         struct ak4113 *chip = snd_kcontrol_chi    217         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
218         unsigned char reg = kcontrol->private_    218         unsigned char reg = kcontrol->private_value & 0xff;
219         unsigned char bit = (kcontrol->private    219         unsigned char bit = (kcontrol->private_value >> 8) & 0xff;
220         unsigned char inv = (kcontrol->private    220         unsigned char inv = (kcontrol->private_value >> 31) & 1;
221                                                   221 
222         ucontrol->value.integer.value[0] =        222         ucontrol->value.integer.value[0] =
223                 ((reg_read(chip, reg) & (1 <<     223                 ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv;
224         return 0;                                 224         return 0;
225 }                                                 225 }
226                                                   226 
227 static int snd_ak4113_rx_info(struct snd_kcont    227 static int snd_ak4113_rx_info(struct snd_kcontrol *kcontrol,
228                               struct snd_ctl_e    228                               struct snd_ctl_elem_info *uinfo)
229 {                                                 229 {
230         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    230         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
231         uinfo->count = 1;                         231         uinfo->count = 1;
232         uinfo->value.integer.min = 0;             232         uinfo->value.integer.min = 0;
233         uinfo->value.integer.max = 5;             233         uinfo->value.integer.max = 5;
234         return 0;                                 234         return 0;
235 }                                                 235 }
236                                                   236 
237 static int snd_ak4113_rx_get(struct snd_kcontr    237 static int snd_ak4113_rx_get(struct snd_kcontrol *kcontrol,
238                              struct snd_ctl_el    238                              struct snd_ctl_elem_value *ucontrol)
239 {                                                 239 {
240         struct ak4113 *chip = snd_kcontrol_chi    240         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
241                                                   241 
242         ucontrol->value.integer.value[0] =        242         ucontrol->value.integer.value[0] =
243                 (AK4113_IPS(chip->regmap[AK411    243                 (AK4113_IPS(chip->regmap[AK4113_REG_IO1]));
244         return 0;                                 244         return 0;
245 }                                                 245 }
246                                                   246 
247 static int snd_ak4113_rx_put(struct snd_kcontr    247 static int snd_ak4113_rx_put(struct snd_kcontrol *kcontrol,
248                              struct snd_ctl_el    248                              struct snd_ctl_elem_value *ucontrol)
249 {                                                 249 {
250         struct ak4113 *chip = snd_kcontrol_chi    250         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
251         int change;                               251         int change;
252         u8 old_val;                               252         u8 old_val;
253                                                   253 
254         spin_lock_irq(&chip->lock);               254         spin_lock_irq(&chip->lock);
255         old_val = chip->regmap[AK4113_REG_IO1]    255         old_val = chip->regmap[AK4113_REG_IO1];
256         change = ucontrol->value.integer.value    256         change = ucontrol->value.integer.value[0] != AK4113_IPS(old_val);
257         if (change)                               257         if (change)
258                 reg_write(chip, AK4113_REG_IO1    258                 reg_write(chip, AK4113_REG_IO1,
259                                 (old_val & (~A    259                                 (old_val & (~AK4113_IPS(0xff))) |
260                                 (AK4113_IPS(uc    260                                 (AK4113_IPS(ucontrol->value.integer.value[0])));
261         spin_unlock_irq(&chip->lock);             261         spin_unlock_irq(&chip->lock);
262         return change;                            262         return change;
263 }                                                 263 }
264                                                   264 
265 static int snd_ak4113_rate_info(struct snd_kco    265 static int snd_ak4113_rate_info(struct snd_kcontrol *kcontrol,
266                                 struct snd_ctl    266                                 struct snd_ctl_elem_info *uinfo)
267 {                                                 267 {
268         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    268         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
269         uinfo->count = 1;                         269         uinfo->count = 1;
270         uinfo->value.integer.min = 0;             270         uinfo->value.integer.min = 0;
271         uinfo->value.integer.max = 192000;        271         uinfo->value.integer.max = 192000;
272         return 0;                                 272         return 0;
273 }                                                 273 }
274                                                   274 
275 static int snd_ak4113_rate_get(struct snd_kcon    275 static int snd_ak4113_rate_get(struct snd_kcontrol *kcontrol,
276                                struct snd_ctl_    276                                struct snd_ctl_elem_value *ucontrol)
277 {                                                 277 {
278         struct ak4113 *chip = snd_kcontrol_chi    278         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
279                                                   279 
280         ucontrol->value.integer.value[0] = ext    280         ucontrol->value.integer.value[0] = external_rate(reg_read(chip,
281                                 AK4113_REG_RCS    281                                 AK4113_REG_RCS1));
282         return 0;                                 282         return 0;
283 }                                                 283 }
284                                                   284 
285 static int snd_ak4113_spdif_info(struct snd_kc    285 static int snd_ak4113_spdif_info(struct snd_kcontrol *kcontrol,
286                 struct snd_ctl_elem_info *uinf    286                 struct snd_ctl_elem_info *uinfo)
287 {                                                 287 {
288         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC9    288         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
289         uinfo->count = 1;                         289         uinfo->count = 1;
290         return 0;                                 290         return 0;
291 }                                                 291 }
292                                                   292 
293 static int snd_ak4113_spdif_get(struct snd_kco    293 static int snd_ak4113_spdif_get(struct snd_kcontrol *kcontrol,
294                                 struct snd_ctl    294                                 struct snd_ctl_elem_value *ucontrol)
295 {                                                 295 {
296         struct ak4113 *chip = snd_kcontrol_chi    296         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
297         unsigned i;                               297         unsigned i;
298                                                   298 
299         for (i = 0; i < AK4113_REG_RXCSB_SIZE;    299         for (i = 0; i < AK4113_REG_RXCSB_SIZE; i++)
300                 ucontrol->value.iec958.status[    300                 ucontrol->value.iec958.status[i] = reg_read(chip,
301                                 AK4113_REG_RXC    301                                 AK4113_REG_RXCSB0 + i);
302         return 0;                                 302         return 0;
303 }                                                 303 }
304                                                   304 
305 static int snd_ak4113_spdif_mask_info(struct s    305 static int snd_ak4113_spdif_mask_info(struct snd_kcontrol *kcontrol,
306                 struct snd_ctl_elem_info *uinf    306                 struct snd_ctl_elem_info *uinfo)
307 {                                                 307 {
308         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC9    308         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
309         uinfo->count = 1;                         309         uinfo->count = 1;
310         return 0;                                 310         return 0;
311 }                                                 311 }
312                                                   312 
313 static int snd_ak4113_spdif_mask_get(struct sn    313 static int snd_ak4113_spdif_mask_get(struct snd_kcontrol *kcontrol,
314                                       struct s    314                                       struct snd_ctl_elem_value *ucontrol)
315 {                                                 315 {
316         memset(ucontrol->value.iec958.status,     316         memset(ucontrol->value.iec958.status, 0xff, AK4113_REG_RXCSB_SIZE);
317         return 0;                                 317         return 0;
318 }                                                 318 }
319                                                   319 
320 static int snd_ak4113_spdif_pinfo(struct snd_k    320 static int snd_ak4113_spdif_pinfo(struct snd_kcontrol *kcontrol,
321                 struct snd_ctl_elem_info *uinf    321                 struct snd_ctl_elem_info *uinfo)
322 {                                                 322 {
323         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    323         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
324         uinfo->value.integer.min = 0;             324         uinfo->value.integer.min = 0;
325         uinfo->value.integer.max = 0xffff;        325         uinfo->value.integer.max = 0xffff;
326         uinfo->count = 4;                         326         uinfo->count = 4;
327         return 0;                                 327         return 0;
328 }                                                 328 }
329                                                   329 
330 static int snd_ak4113_spdif_pget(struct snd_kc    330 static int snd_ak4113_spdif_pget(struct snd_kcontrol *kcontrol,
331                                  struct snd_ct    331                                  struct snd_ctl_elem_value *ucontrol)
332 {                                                 332 {
333         struct ak4113 *chip = snd_kcontrol_chi    333         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
334         unsigned short tmp;                       334         unsigned short tmp;
335                                                   335 
336         ucontrol->value.integer.value[0] = 0xf    336         ucontrol->value.integer.value[0] = 0xf8f2;
337         ucontrol->value.integer.value[1] = 0x4    337         ucontrol->value.integer.value[1] = 0x4e1f;
338         tmp = reg_read(chip, AK4113_REG_Pc0) |    338         tmp = reg_read(chip, AK4113_REG_Pc0) |
339                 (reg_read(chip, AK4113_REG_Pc1    339                 (reg_read(chip, AK4113_REG_Pc1) << 8);
340         ucontrol->value.integer.value[2] = tmp    340         ucontrol->value.integer.value[2] = tmp;
341         tmp = reg_read(chip, AK4113_REG_Pd0) |    341         tmp = reg_read(chip, AK4113_REG_Pd0) |
342                 (reg_read(chip, AK4113_REG_Pd1    342                 (reg_read(chip, AK4113_REG_Pd1) << 8);
343         ucontrol->value.integer.value[3] = tmp    343         ucontrol->value.integer.value[3] = tmp;
344         return 0;                                 344         return 0;
345 }                                                 345 }
346                                                   346 
347 static int snd_ak4113_spdif_qinfo(struct snd_k    347 static int snd_ak4113_spdif_qinfo(struct snd_kcontrol *kcontrol,
348                 struct snd_ctl_elem_info *uinf    348                 struct snd_ctl_elem_info *uinfo)
349 {                                                 349 {
350         uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTE    350         uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
351         uinfo->count = AK4113_REG_QSUB_SIZE;      351         uinfo->count = AK4113_REG_QSUB_SIZE;
352         return 0;                                 352         return 0;
353 }                                                 353 }
354                                                   354 
355 static int snd_ak4113_spdif_qget(struct snd_kc    355 static int snd_ak4113_spdif_qget(struct snd_kcontrol *kcontrol,
356                                  struct snd_ct    356                                  struct snd_ctl_elem_value *ucontrol)
357 {                                                 357 {
358         struct ak4113 *chip = snd_kcontrol_chi    358         struct ak4113 *chip = snd_kcontrol_chip(kcontrol);
359         unsigned i;                               359         unsigned i;
360                                                   360 
361         for (i = 0; i < AK4113_REG_QSUB_SIZE;     361         for (i = 0; i < AK4113_REG_QSUB_SIZE; i++)
362                 ucontrol->value.bytes.data[i]     362                 ucontrol->value.bytes.data[i] = reg_read(chip,
363                                 AK4113_REG_QSU    363                                 AK4113_REG_QSUB_ADDR + i);
364         return 0;                                 364         return 0;
365 }                                                 365 }
366                                                   366 
367 /* Don't forget to change AK4113_CONTROLS defi    367 /* Don't forget to change AK4113_CONTROLS define!!! */
368 static struct snd_kcontrol_new snd_ak4113_iec9    368 static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = {
369 {                                                 369 {
370         .iface =        SNDRV_CTL_ELEM_IFACE_P    370         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
371         .name =         "IEC958 Parity Errors"    371         .name =         "IEC958 Parity Errors",
372         .access =       SNDRV_CTL_ELEM_ACCESS_    372         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
373                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    373                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
374         .info =         snd_ak4113_in_error_in    374         .info =         snd_ak4113_in_error_info,
375         .get =          snd_ak4113_in_error_ge    375         .get =          snd_ak4113_in_error_get,
376         .private_value = offsetof(struct ak411    376         .private_value = offsetof(struct ak4113, parity_errors),
377 },                                                377 },
378 {                                                 378 {
379         .iface =        SNDRV_CTL_ELEM_IFACE_P    379         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
380         .name =         "IEC958 V-Bit Errors",    380         .name =         "IEC958 V-Bit Errors",
381         .access =       SNDRV_CTL_ELEM_ACCESS_    381         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
382                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    382                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
383         .info =         snd_ak4113_in_error_in    383         .info =         snd_ak4113_in_error_info,
384         .get =          snd_ak4113_in_error_ge    384         .get =          snd_ak4113_in_error_get,
385         .private_value = offsetof(struct ak411    385         .private_value = offsetof(struct ak4113, v_bit_errors),
386 },                                                386 },
387 {                                                 387 {
388         .iface =        SNDRV_CTL_ELEM_IFACE_P    388         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
389         .name =         "IEC958 C-CRC Errors",    389         .name =         "IEC958 C-CRC Errors",
390         .access =       SNDRV_CTL_ELEM_ACCESS_    390         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
391                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    391                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
392         .info =         snd_ak4113_in_error_in    392         .info =         snd_ak4113_in_error_info,
393         .get =          snd_ak4113_in_error_ge    393         .get =          snd_ak4113_in_error_get,
394         .private_value = offsetof(struct ak411    394         .private_value = offsetof(struct ak4113, ccrc_errors),
395 },                                                395 },
396 {                                                 396 {
397         .iface =        SNDRV_CTL_ELEM_IFACE_P    397         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
398         .name =         "IEC958 Q-CRC Errors",    398         .name =         "IEC958 Q-CRC Errors",
399         .access =       SNDRV_CTL_ELEM_ACCESS_    399         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
400                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    400                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
401         .info =         snd_ak4113_in_error_in    401         .info =         snd_ak4113_in_error_info,
402         .get =          snd_ak4113_in_error_ge    402         .get =          snd_ak4113_in_error_get,
403         .private_value = offsetof(struct ak411    403         .private_value = offsetof(struct ak4113, qcrc_errors),
404 },                                                404 },
405 {                                                 405 {
406         .iface =        SNDRV_CTL_ELEM_IFACE_P    406         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
407         .name =         "IEC958 External Rate"    407         .name =         "IEC958 External Rate",
408         .access =       SNDRV_CTL_ELEM_ACCESS_    408         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
409                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    409                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
410         .info =         snd_ak4113_rate_info,     410         .info =         snd_ak4113_rate_info,
411         .get =          snd_ak4113_rate_get,      411         .get =          snd_ak4113_rate_get,
412 },                                                412 },
413 {                                                 413 {
414         .iface =        SNDRV_CTL_ELEM_IFACE_P    414         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
415         .name =         SNDRV_CTL_NAME_IEC958(    415         .name =         SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
416         .access =       SNDRV_CTL_ELEM_ACCESS_    416         .access =       SNDRV_CTL_ELEM_ACCESS_READ,
417         .info =         snd_ak4113_spdif_mask_    417         .info =         snd_ak4113_spdif_mask_info,
418         .get =          snd_ak4113_spdif_mask_    418         .get =          snd_ak4113_spdif_mask_get,
419 },                                                419 },
420 {                                                 420 {
421         .iface =        SNDRV_CTL_ELEM_IFACE_P    421         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
422         .name =         SNDRV_CTL_NAME_IEC958(    422         .name =         SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
423         .access =       SNDRV_CTL_ELEM_ACCESS_    423         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
424                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    424                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
425         .info =         snd_ak4113_spdif_info,    425         .info =         snd_ak4113_spdif_info,
426         .get =          snd_ak4113_spdif_get,     426         .get =          snd_ak4113_spdif_get,
427 },                                                427 },
428 {                                                 428 {
429         .iface =        SNDRV_CTL_ELEM_IFACE_P    429         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
430         .name =         "IEC958 Preamble Captu    430         .name =         "IEC958 Preamble Capture Default",
431         .access =       SNDRV_CTL_ELEM_ACCESS_    431         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
432                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    432                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
433         .info =         snd_ak4113_spdif_pinfo    433         .info =         snd_ak4113_spdif_pinfo,
434         .get =          snd_ak4113_spdif_pget,    434         .get =          snd_ak4113_spdif_pget,
435 },                                                435 },
436 {                                                 436 {
437         .iface =        SNDRV_CTL_ELEM_IFACE_P    437         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
438         .name =         "IEC958 Q-subcode Capt    438         .name =         "IEC958 Q-subcode Capture Default",
439         .access =       SNDRV_CTL_ELEM_ACCESS_    439         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
440                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    440                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
441         .info =         snd_ak4113_spdif_qinfo    441         .info =         snd_ak4113_spdif_qinfo,
442         .get =          snd_ak4113_spdif_qget,    442         .get =          snd_ak4113_spdif_qget,
443 },                                                443 },
444 {                                                 444 {
445         .iface =        SNDRV_CTL_ELEM_IFACE_P    445         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
446         .name =         "IEC958 Audio",           446         .name =         "IEC958 Audio",
447         .access =       SNDRV_CTL_ELEM_ACCESS_    447         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
448                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    448                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
449         .info =         snd_ak4113_in_bit_info    449         .info =         snd_ak4113_in_bit_info,
450         .get =          snd_ak4113_in_bit_get,    450         .get =          snd_ak4113_in_bit_get,
451         .private_value = (1<<31) | (1<<8) | AK    451         .private_value = (1<<31) | (1<<8) | AK4113_REG_RCS0,
452 },                                                452 },
453 {                                                 453 {
454         .iface =        SNDRV_CTL_ELEM_IFACE_P    454         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
455         .name =         "IEC958 Non-PCM Bitstr    455         .name =         "IEC958 Non-PCM Bitstream",
456         .access =       SNDRV_CTL_ELEM_ACCESS_    456         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
457                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    457                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
458         .info =         snd_ak4113_in_bit_info    458         .info =         snd_ak4113_in_bit_info,
459         .get =          snd_ak4113_in_bit_get,    459         .get =          snd_ak4113_in_bit_get,
460         .private_value = (0<<8) | AK4113_REG_R    460         .private_value = (0<<8) | AK4113_REG_RCS1,
461 },                                                461 },
462 {                                                 462 {
463         .iface =        SNDRV_CTL_ELEM_IFACE_P    463         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
464         .name =         "IEC958 DTS Bitstream"    464         .name =         "IEC958 DTS Bitstream",
465         .access =       SNDRV_CTL_ELEM_ACCESS_    465         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
466                 SNDRV_CTL_ELEM_ACCESS_VOLATILE    466                 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
467         .info =         snd_ak4113_in_bit_info    467         .info =         snd_ak4113_in_bit_info,
468         .get =          snd_ak4113_in_bit_get,    468         .get =          snd_ak4113_in_bit_get,
469         .private_value = (1<<8) | AK4113_REG_R    469         .private_value = (1<<8) | AK4113_REG_RCS1,
470 },                                                470 },
471 {                                                 471 {
472         .iface =        SNDRV_CTL_ELEM_IFACE_P    472         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
473         .name =         "AK4113 Input Select",    473         .name =         "AK4113 Input Select",
474         .access =       SNDRV_CTL_ELEM_ACCESS_    474         .access =       SNDRV_CTL_ELEM_ACCESS_READ |
475                 SNDRV_CTL_ELEM_ACCESS_WRITE,      475                 SNDRV_CTL_ELEM_ACCESS_WRITE,
476         .info =         snd_ak4113_rx_info,       476         .info =         snd_ak4113_rx_info,
477         .get =          snd_ak4113_rx_get,        477         .get =          snd_ak4113_rx_get,
478         .put =          snd_ak4113_rx_put,        478         .put =          snd_ak4113_rx_put,
479 }                                                 479 }
480 };                                                480 };
481                                                   481 
482 static void snd_ak4113_proc_regs_read(struct s    482 static void snd_ak4113_proc_regs_read(struct snd_info_entry *entry,
483                 struct snd_info_buffer *buffer    483                 struct snd_info_buffer *buffer)
484 {                                                 484 {
485         struct ak4113 *ak4113 = entry->private    485         struct ak4113 *ak4113 = entry->private_data;
486         int reg, val;                             486         int reg, val;
487         /* all ak4113 registers 0x00 - 0x1c */    487         /* all ak4113 registers 0x00 - 0x1c */
488         for (reg = 0; reg < 0x1d; reg++) {        488         for (reg = 0; reg < 0x1d; reg++) {
489                 val = reg_read(ak4113, reg);      489                 val = reg_read(ak4113, reg);
490                 snd_iprintf(buffer, "0x%02x =     490                 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
491         }                                         491         }
492 }                                                 492 }
493                                                   493 
494 static void snd_ak4113_proc_init(struct ak4113    494 static void snd_ak4113_proc_init(struct ak4113 *ak4113)
495 {                                                 495 {
496         struct snd_info_entry *entry;             496         struct snd_info_entry *entry;
497         if (!snd_card_proc_new(ak4113->card, "    497         if (!snd_card_proc_new(ak4113->card, "ak4113", &entry))
498                 snd_info_set_text_ops(entry, a    498                 snd_info_set_text_ops(entry, ak4113, snd_ak4113_proc_regs_read);
499 }                                                 499 }
500                                                   500 
501 int snd_ak4113_build(struct ak4113 *ak4113,       501 int snd_ak4113_build(struct ak4113 *ak4113,
502                 struct snd_pcm_substream *cap_    502                 struct snd_pcm_substream *cap_substream)
503 {                                                 503 {
504         struct snd_kcontrol *kctl;                504         struct snd_kcontrol *kctl;
505         unsigned int idx;                         505         unsigned int idx;
506         int err;                                  506         int err;
507                                                   507 
508         if (snd_BUG_ON(!cap_substream))           508         if (snd_BUG_ON(!cap_substream))
509                 return -EINVAL;                   509                 return -EINVAL;
510         ak4113->substream = cap_substream;        510         ak4113->substream = cap_substream;
511         for (idx = 0; idx < AK4113_CONTROLS; i    511         for (idx = 0; idx < AK4113_CONTROLS; idx++) {
512                 kctl = snd_ctl_new1(&snd_ak411    512                 kctl = snd_ctl_new1(&snd_ak4113_iec958_controls[idx], ak4113);
513                 if (kctl == NULL)                 513                 if (kctl == NULL)
514                         return -ENOMEM;           514                         return -ENOMEM;
515                 kctl->id.device = cap_substrea    515                 kctl->id.device = cap_substream->pcm->device;
516                 kctl->id.subdevice = cap_subst    516                 kctl->id.subdevice = cap_substream->number;
517                 err = snd_ctl_add(ak4113->card    517                 err = snd_ctl_add(ak4113->card, kctl);
518                 if (err < 0)                      518                 if (err < 0)
519                         return err;               519                         return err;
520                 ak4113->kctls[idx] = kctl;        520                 ak4113->kctls[idx] = kctl;
521         }                                         521         }
522         snd_ak4113_proc_init(ak4113);             522         snd_ak4113_proc_init(ak4113);
523         /* trigger workq */                       523         /* trigger workq */
524         schedule_delayed_work(&ak4113->work, H    524         schedule_delayed_work(&ak4113->work, HZ / 10);
525         return 0;                                 525         return 0;
526 }                                                 526 }
527 EXPORT_SYMBOL_GPL(snd_ak4113_build);              527 EXPORT_SYMBOL_GPL(snd_ak4113_build);
528                                                   528 
529 int snd_ak4113_external_rate(struct ak4113 *ak    529 int snd_ak4113_external_rate(struct ak4113 *ak4113)
530 {                                                 530 {
531         unsigned char rcs1;                       531         unsigned char rcs1;
532                                                   532 
533         rcs1 = reg_read(ak4113, AK4113_REG_RCS    533         rcs1 = reg_read(ak4113, AK4113_REG_RCS1);
534         return external_rate(rcs1);               534         return external_rate(rcs1);
535 }                                                 535 }
536 EXPORT_SYMBOL_GPL(snd_ak4113_external_rate);      536 EXPORT_SYMBOL_GPL(snd_ak4113_external_rate);
537                                                   537 
538 int snd_ak4113_check_rate_and_errors(struct ak    538 int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags)
539 {                                                 539 {
540         struct snd_pcm_runtime *runtime =         540         struct snd_pcm_runtime *runtime =
541                 ak4113->substream ? ak4113->su    541                 ak4113->substream ? ak4113->substream->runtime : NULL;
542         unsigned long _flags;                     542         unsigned long _flags;
543         int res = 0;                              543         int res = 0;
544         unsigned char rcs0, rcs1, rcs2;           544         unsigned char rcs0, rcs1, rcs2;
545         unsigned char c0, c1;                     545         unsigned char c0, c1;
546                                                   546 
547         rcs1 = reg_read(ak4113, AK4113_REG_RCS    547         rcs1 = reg_read(ak4113, AK4113_REG_RCS1);
548         if (flags & AK4113_CHECK_NO_STAT)         548         if (flags & AK4113_CHECK_NO_STAT)
549                 goto __rate;                      549                 goto __rate;
550         rcs0 = reg_read(ak4113, AK4113_REG_RCS    550         rcs0 = reg_read(ak4113, AK4113_REG_RCS0);
551         rcs2 = reg_read(ak4113, AK4113_REG_RCS    551         rcs2 = reg_read(ak4113, AK4113_REG_RCS2);
552         spin_lock_irqsave(&ak4113->lock, _flag    552         spin_lock_irqsave(&ak4113->lock, _flags);
553         if (rcs0 & AK4113_PAR)                    553         if (rcs0 & AK4113_PAR)
554                 ak4113->parity_errors++;          554                 ak4113->parity_errors++;
555         if (rcs0 & AK4113_V)                      555         if (rcs0 & AK4113_V)
556                 ak4113->v_bit_errors++;           556                 ak4113->v_bit_errors++;
557         if (rcs2 & AK4113_CCRC)                   557         if (rcs2 & AK4113_CCRC)
558                 ak4113->ccrc_errors++;            558                 ak4113->ccrc_errors++;
559         if (rcs2 & AK4113_QCRC)                   559         if (rcs2 & AK4113_QCRC)
560                 ak4113->qcrc_errors++;            560                 ak4113->qcrc_errors++;
561         c0 = (ak4113->rcs0 & (AK4113_QINT | AK    561         c0 = (ak4113->rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC |
562                                 AK4113_AUDION     562                                 AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK)) ^
563                 (rcs0 & (AK4113_QINT | AK4113_    563                 (rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC |
564                          AK4113_AUDION | AK411    564                          AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK));
565         c1 = (ak4113->rcs1 & (AK4113_DTSCD | A    565         c1 = (ak4113->rcs1 & (AK4113_DTSCD | AK4113_NPCM | AK4113_PEM |
566                                 AK4113_DAT | 0    566                                 AK4113_DAT | 0xf0)) ^
567                 (rcs1 & (AK4113_DTSCD | AK4113    567                 (rcs1 & (AK4113_DTSCD | AK4113_NPCM | AK4113_PEM |
568                          AK4113_DAT | 0xf0));     568                          AK4113_DAT | 0xf0));
569         ak4113->rcs0 = rcs0 & ~(AK4113_QINT |     569         ak4113->rcs0 = rcs0 & ~(AK4113_QINT | AK4113_CINT | AK4113_STC);
570         ak4113->rcs1 = rcs1;                      570         ak4113->rcs1 = rcs1;
571         ak4113->rcs2 = rcs2;                      571         ak4113->rcs2 = rcs2;
572         spin_unlock_irqrestore(&ak4113->lock,     572         spin_unlock_irqrestore(&ak4113->lock, _flags);
573                                                   573 
574         if (rcs0 & AK4113_PAR)                    574         if (rcs0 & AK4113_PAR)
575                 snd_ctl_notify(ak4113->card, S    575                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
576                                 &ak4113->kctls    576                                 &ak4113->kctls[0]->id);
577         if (rcs0 & AK4113_V)                      577         if (rcs0 & AK4113_V)
578                 snd_ctl_notify(ak4113->card, S    578                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
579                                 &ak4113->kctls    579                                 &ak4113->kctls[1]->id);
580         if (rcs2 & AK4113_CCRC)                   580         if (rcs2 & AK4113_CCRC)
581                 snd_ctl_notify(ak4113->card, S    581                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
582                                 &ak4113->kctls    582                                 &ak4113->kctls[2]->id);
583         if (rcs2 & AK4113_QCRC)                   583         if (rcs2 & AK4113_QCRC)
584                 snd_ctl_notify(ak4113->card, S    584                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
585                                 &ak4113->kctls    585                                 &ak4113->kctls[3]->id);
586                                                   586 
587         /* rate change */                         587         /* rate change */
588         if (c1 & 0xf0)                            588         if (c1 & 0xf0)
589                 snd_ctl_notify(ak4113->card, S    589                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
590                                 &ak4113->kctls    590                                 &ak4113->kctls[4]->id);
591                                                   591 
592         if ((c1 & AK4113_PEM) | (c0 & AK4113_C    592         if ((c1 & AK4113_PEM) | (c0 & AK4113_CINT))
593                 snd_ctl_notify(ak4113->card, S    593                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
594                                 &ak4113->kctls    594                                 &ak4113->kctls[6]->id);
595         if (c0 & AK4113_QINT)                     595         if (c0 & AK4113_QINT)
596                 snd_ctl_notify(ak4113->card, S    596                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
597                                 &ak4113->kctls    597                                 &ak4113->kctls[8]->id);
598                                                   598 
599         if (c0 & AK4113_AUDION)                   599         if (c0 & AK4113_AUDION)
600                 snd_ctl_notify(ak4113->card, S    600                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
601                                 &ak4113->kctls    601                                 &ak4113->kctls[9]->id);
602         if (c1 & AK4113_NPCM)                     602         if (c1 & AK4113_NPCM)
603                 snd_ctl_notify(ak4113->card, S    603                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
604                                 &ak4113->kctls    604                                 &ak4113->kctls[10]->id);
605         if (c1 & AK4113_DTSCD)                    605         if (c1 & AK4113_DTSCD)
606                 snd_ctl_notify(ak4113->card, S    606                 snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
607                                 &ak4113->kctls    607                                 &ak4113->kctls[11]->id);
608                                                   608 
609         if (ak4113->change_callback && (c0 | c    609         if (ak4113->change_callback && (c0 | c1) != 0)
610                 ak4113->change_callback(ak4113    610                 ak4113->change_callback(ak4113, c0, c1);
611                                                   611 
612 __rate:                                           612 __rate:
613         /* compare rate */                        613         /* compare rate */
614         res = external_rate(rcs1);                614         res = external_rate(rcs1);
615         if (!(flags & AK4113_CHECK_NO_RATE) &&    615         if (!(flags & AK4113_CHECK_NO_RATE) && runtime &&
616                         (runtime->rate != res)    616                         (runtime->rate != res)) {
617                 snd_pcm_stream_lock_irqsave(ak    617                 snd_pcm_stream_lock_irqsave(ak4113->substream, _flags);
618                 if (snd_pcm_running(ak4113->su    618                 if (snd_pcm_running(ak4113->substream)) {
619                         /*printk(KERN_DEBUG "r    619                         /*printk(KERN_DEBUG "rate changed (%i <- %i)\n",
620                          * runtime->rate, res)    620                          * runtime->rate, res); */
621                         snd_pcm_stop(ak4113->s    621                         snd_pcm_stop(ak4113->substream,
622                                         SNDRV_    622                                         SNDRV_PCM_STATE_DRAINING);
623                         wake_up(&runtime->slee    623                         wake_up(&runtime->sleep);
624                         res = 1;                  624                         res = 1;
625                 }                                 625                 }
626                 snd_pcm_stream_unlock_irqresto    626                 snd_pcm_stream_unlock_irqrestore(ak4113->substream, _flags);
627         }                                         627         }
628         return res;                               628         return res;
629 }                                                 629 }
630 EXPORT_SYMBOL_GPL(snd_ak4113_check_rate_and_er    630 EXPORT_SYMBOL_GPL(snd_ak4113_check_rate_and_errors);
631                                                   631 
632 static void ak4113_stats(struct work_struct *w    632 static void ak4113_stats(struct work_struct *work)
633 {                                                 633 {
634         struct ak4113 *chip = container_of(wor    634         struct ak4113 *chip = container_of(work, struct ak4113, work.work);
635                                                   635 
636         if (atomic_inc_return(&chip->wq_proces    636         if (atomic_inc_return(&chip->wq_processing) == 1)
637                 snd_ak4113_check_rate_and_erro    637                 snd_ak4113_check_rate_and_errors(chip, chip->check_flags);
638                                                   638 
639         if (atomic_dec_and_test(&chip->wq_proc    639         if (atomic_dec_and_test(&chip->wq_processing))
640                 schedule_delayed_work(&chip->w    640                 schedule_delayed_work(&chip->work, HZ / 10);
641 }                                                 641 }
642                                                   642 
643 #ifdef CONFIG_PM                                  643 #ifdef CONFIG_PM
644 void snd_ak4113_suspend(struct ak4113 *chip)      644 void snd_ak4113_suspend(struct ak4113 *chip)
645 {                                                 645 {
646         atomic_inc(&chip->wq_processing); /* d    646         atomic_inc(&chip->wq_processing); /* don't schedule new work */
647         cancel_delayed_work_sync(&chip->work);    647         cancel_delayed_work_sync(&chip->work);
648 }                                                 648 }
649 EXPORT_SYMBOL(snd_ak4113_suspend);                649 EXPORT_SYMBOL(snd_ak4113_suspend);
650                                                   650 
651 void snd_ak4113_resume(struct ak4113 *chip)       651 void snd_ak4113_resume(struct ak4113 *chip)
652 {                                                 652 {
653         atomic_dec(&chip->wq_processing);         653         atomic_dec(&chip->wq_processing);
654         snd_ak4113_reinit(chip);                  654         snd_ak4113_reinit(chip);
655 }                                                 655 }
656 EXPORT_SYMBOL(snd_ak4113_resume);                 656 EXPORT_SYMBOL(snd_ak4113_resume);
657 #endif                                            657 #endif
658                                                   658 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp