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

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

Version: ~ [ linux-5.5 ] ~ [ linux-5.4.15 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.98 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.167 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.211 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.211 ] ~ [ 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 (Version linux-4.1.52) and /sound/i2c/other/ak4113.c (Version linux-3.2.102)


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

~ [ 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