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

TOMOYO Linux Cross Reference
Linux/sound/ppc/awacs.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/ppc/awacs.c (Version linux-6.11.5) and /sound/ppc/awacs.c (Version linux-4.16.18)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /*                                                  1 /*
  3  * PMac AWACS lowlevel functions                    2  * PMac AWACS lowlevel functions
  4  *                                                  3  *
  5  * Copyright (c) by Takashi Iwai <tiwai@suse.d      4  * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  6  * code based on dmasound.c.                        5  * code based on dmasound.c.
                                                   >>   6  *
                                                   >>   7  *   This program is free software; you can redistribute it and/or modify
                                                   >>   8  *   it under the terms of the GNU General Public License as published by
                                                   >>   9  *   the Free Software Foundation; either version 2 of the License, or
                                                   >>  10  *   (at your option) any later version.
                                                   >>  11  *
                                                   >>  12  *   This program is distributed in the hope that it will be useful,
                                                   >>  13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                   >>  14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                                                   >>  15  *   GNU General Public License for more details.
                                                   >>  16  *
                                                   >>  17  *   You should have received a copy of the GNU General Public License
                                                   >>  18  *   along with this program; if not, write to the Free Software
                                                   >>  19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  7  */                                                20  */
  8                                                    21 
  9                                                    22 
 10 #include <linux/io.h>                              23 #include <linux/io.h>
 11 #include <asm/nvram.h>                             24 #include <asm/nvram.h>
 12 #include <linux/init.h>                            25 #include <linux/init.h>
 13 #include <linux/delay.h>                           26 #include <linux/delay.h>
 14 #include <linux/of.h>                          << 
 15 #include <linux/slab.h>                            27 #include <linux/slab.h>
 16 #include <sound/core.h>                            28 #include <sound/core.h>
 17 #include "pmac.h"                                  29 #include "pmac.h"
 18                                                    30 
 19                                                    31 
 20 #ifdef CONFIG_ADB_CUDA                             32 #ifdef CONFIG_ADB_CUDA
 21 #define PMAC_AMP_AVAIL                             33 #define PMAC_AMP_AVAIL
 22 #endif                                             34 #endif
 23                                                    35 
 24 #ifdef PMAC_AMP_AVAIL                              36 #ifdef PMAC_AMP_AVAIL
 25 struct awacs_amp {                                 37 struct awacs_amp {
 26         unsigned char amp_master;                  38         unsigned char amp_master;
 27         unsigned char amp_vol[2][2];               39         unsigned char amp_vol[2][2];
 28         unsigned char amp_tone[2];                 40         unsigned char amp_tone[2];
 29 };                                                 41 };
 30                                                    42 
 31 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CT     43 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
 32                                                    44 
 33 #endif /* PMAC_AMP_AVAIL */                        45 #endif /* PMAC_AMP_AVAIL */
 34                                                    46 
 35                                                    47 
 36 static void snd_pmac_screamer_wait(struct snd_     48 static void snd_pmac_screamer_wait(struct snd_pmac *chip)
 37 {                                                  49 {
 38         long timeout = 2000;                       50         long timeout = 2000;
 39         while (!(in_le32(&chip->awacs->codec_s     51         while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
 40                 mdelay(1);                         52                 mdelay(1);
 41                 if (! --timeout) {                 53                 if (! --timeout) {
 42                         snd_printd("snd_pmac_s     54                         snd_printd("snd_pmac_screamer_wait timeout\n");
 43                         break;                     55                         break;
 44                 }                                  56                 }
 45         }                                          57         }
 46 }                                                  58 }
 47                                                    59 
 48 /*                                                 60 /*
 49  * write AWACS register                            61  * write AWACS register
 50  */                                                62  */
 51 static void                                        63 static void
 52 snd_pmac_awacs_write(struct snd_pmac *chip, in     64 snd_pmac_awacs_write(struct snd_pmac *chip, int val)
 53 {                                                  65 {
 54         long timeout = 5000000;                    66         long timeout = 5000000;
 55                                                    67 
 56         if (chip->model == PMAC_SCREAMER)          68         if (chip->model == PMAC_SCREAMER)
 57                 snd_pmac_screamer_wait(chip);      69                 snd_pmac_screamer_wait(chip);
 58         out_le32(&chip->awacs->codec_ctrl, val     70         out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
 59         while (in_le32(&chip->awacs->codec_ctr     71         while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
 60                 if (! --timeout) {                 72                 if (! --timeout) {
 61                         snd_printd("snd_pmac_a     73                         snd_printd("snd_pmac_awacs_write timeout\n");
 62                         break;                     74                         break;
 63                 }                                  75                 }
 64         }                                          76         }
 65 }                                                  77 }
 66                                                    78 
 67 static void                                        79 static void
 68 snd_pmac_awacs_write_reg(struct snd_pmac *chip     80 snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
 69 {                                                  81 {
 70         snd_pmac_awacs_write(chip, val | (reg      82         snd_pmac_awacs_write(chip, val | (reg << 12));
 71         chip->awacs_reg[reg] = val;                83         chip->awacs_reg[reg] = val;
 72 }                                                  84 }
 73                                                    85 
 74 static void                                        86 static void
 75 snd_pmac_awacs_write_noreg(struct snd_pmac *ch     87 snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
 76 {                                                  88 {
 77         snd_pmac_awacs_write(chip, val | (reg      89         snd_pmac_awacs_write(chip, val | (reg << 12));
 78 }                                                  90 }
 79                                                    91 
 80 #ifdef CONFIG_PM                                   92 #ifdef CONFIG_PM
 81 /* Recalibrate chip */                             93 /* Recalibrate chip */
 82 static void screamer_recalibrate(struct snd_pm     94 static void screamer_recalibrate(struct snd_pmac *chip)
 83 {                                                  95 {
 84         if (chip->model != PMAC_SCREAMER)          96         if (chip->model != PMAC_SCREAMER)
 85                 return;                            97                 return;
 86                                                    98 
 87         /* Sorry for the horrible delays... I      99         /* Sorry for the horrible delays... I hope to get that improved
 88          * by making the whole PM process asyn    100          * by making the whole PM process asynchronous in a future version
 89          */                                       101          */
 90         snd_pmac_awacs_write_noreg(chip, 1, ch    102         snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
 91         if (chip->manufacturer == 0x1)            103         if (chip->manufacturer == 0x1)
 92                 /* delay for broken crystal pa    104                 /* delay for broken crystal part */
 93                 msleep(750);                      105                 msleep(750);
 94         snd_pmac_awacs_write_noreg(chip, 1,       106         snd_pmac_awacs_write_noreg(chip, 1,
 95                                    chip->awacs    107                                    chip->awacs_reg[1] | MASK_RECALIBRATE |
 96                                    MASK_CMUTE     108                                    MASK_CMUTE | MASK_AMUTE);
 97         snd_pmac_awacs_write_noreg(chip, 1, ch    109         snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
 98         snd_pmac_awacs_write_noreg(chip, 6, ch    110         snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
 99 }                                                 111 }
100                                                   112 
101 #else                                             113 #else
102 #define screamer_recalibrate(chip) /* NOP */      114 #define screamer_recalibrate(chip) /* NOP */
103 #endif                                            115 #endif
104                                                   116 
105                                                   117 
106 /*                                                118 /*
107  * additional callback to set the pcm format      119  * additional callback to set the pcm format
108  */                                               120  */
109 static void snd_pmac_awacs_set_format(struct s    121 static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
110 {                                                 122 {
111         chip->awacs_reg[1] &= ~MASK_SAMPLERATE    123         chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
112         chip->awacs_reg[1] |= chip->rate_index    124         chip->awacs_reg[1] |= chip->rate_index << 3;
113         snd_pmac_awacs_write_reg(chip, 1, chip    125         snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
114 }                                                 126 }
115                                                   127 
116                                                   128 
117 /*                                                129 /*
118  * AWACS volume callbacks                         130  * AWACS volume callbacks
119  */                                               131  */
120 /*                                                132 /*
121  * volumes: 0-15 stereo                           133  * volumes: 0-15 stereo
122  */                                               134  */
123 static int snd_pmac_awacs_info_volume(struct s    135 static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
124                                       struct s    136                                       struct snd_ctl_elem_info *uinfo)
125 {                                                 137 {
126         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    138         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
127         uinfo->count = 2;                         139         uinfo->count = 2;
128         uinfo->value.integer.min = 0;             140         uinfo->value.integer.min = 0;
129         uinfo->value.integer.max = 15;            141         uinfo->value.integer.max = 15;
130         return 0;                                 142         return 0;
131 }                                                 143 }
132                                                   144 
133 static int snd_pmac_awacs_get_volume(struct sn    145 static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
134                                      struct sn    146                                      struct snd_ctl_elem_value *ucontrol)
135 {                                                 147 {
136         struct snd_pmac *chip = snd_kcontrol_c    148         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
137         int reg = kcontrol->private_value & 0x    149         int reg = kcontrol->private_value & 0xff;
138         int lshift = (kcontrol->private_value     150         int lshift = (kcontrol->private_value >> 8) & 0xff;
139         int inverted = (kcontrol->private_valu    151         int inverted = (kcontrol->private_value >> 16) & 1;
140         unsigned long flags;                      152         unsigned long flags;
141         int vol[2];                               153         int vol[2];
142                                                   154 
143         spin_lock_irqsave(&chip->reg_lock, fla    155         spin_lock_irqsave(&chip->reg_lock, flags);
144         vol[0] = (chip->awacs_reg[reg] >> lshi    156         vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
145         vol[1] = chip->awacs_reg[reg] & 0xf;      157         vol[1] = chip->awacs_reg[reg] & 0xf;
146         spin_unlock_irqrestore(&chip->reg_lock    158         spin_unlock_irqrestore(&chip->reg_lock, flags);
147         if (inverted) {                           159         if (inverted) {
148                 vol[0] = 0x0f - vol[0];           160                 vol[0] = 0x0f - vol[0];
149                 vol[1] = 0x0f - vol[1];           161                 vol[1] = 0x0f - vol[1];
150         }                                         162         }
151         ucontrol->value.integer.value[0] = vol    163         ucontrol->value.integer.value[0] = vol[0];
152         ucontrol->value.integer.value[1] = vol    164         ucontrol->value.integer.value[1] = vol[1];
153         return 0;                                 165         return 0;
154 }                                                 166 }
155                                                   167 
156 static int snd_pmac_awacs_put_volume(struct sn    168 static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
157                                      struct sn    169                                      struct snd_ctl_elem_value *ucontrol)
158 {                                                 170 {
159         struct snd_pmac *chip = snd_kcontrol_c    171         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
160         int reg = kcontrol->private_value & 0x    172         int reg = kcontrol->private_value & 0xff;
161         int lshift = (kcontrol->private_value     173         int lshift = (kcontrol->private_value >> 8) & 0xff;
162         int inverted = (kcontrol->private_valu    174         int inverted = (kcontrol->private_value >> 16) & 1;
163         int val, oldval;                          175         int val, oldval;
164         unsigned long flags;                      176         unsigned long flags;
165         unsigned int vol[2];                      177         unsigned int vol[2];
166                                                   178 
167         vol[0] = ucontrol->value.integer.value    179         vol[0] = ucontrol->value.integer.value[0];
168         vol[1] = ucontrol->value.integer.value    180         vol[1] = ucontrol->value.integer.value[1];
169         if (vol[0] > 0x0f || vol[1] > 0x0f)       181         if (vol[0] > 0x0f || vol[1] > 0x0f)
170                 return -EINVAL;                   182                 return -EINVAL;
171         if (inverted) {                           183         if (inverted) {
172                 vol[0] = 0x0f - vol[0];           184                 vol[0] = 0x0f - vol[0];
173                 vol[1] = 0x0f - vol[1];           185                 vol[1] = 0x0f - vol[1];
174         }                                         186         }
175         vol[0] &= 0x0f;                           187         vol[0] &= 0x0f;
176         vol[1] &= 0x0f;                           188         vol[1] &= 0x0f;
177         spin_lock_irqsave(&chip->reg_lock, fla    189         spin_lock_irqsave(&chip->reg_lock, flags);
178         oldval = chip->awacs_reg[reg];            190         oldval = chip->awacs_reg[reg];
179         val = oldval & ~(0xf | (0xf << lshift)    191         val = oldval & ~(0xf | (0xf << lshift));
180         val |= vol[0] << lshift;                  192         val |= vol[0] << lshift;
181         val |= vol[1];                            193         val |= vol[1];
182         if (oldval != val)                        194         if (oldval != val)
183                 snd_pmac_awacs_write_reg(chip,    195                 snd_pmac_awacs_write_reg(chip, reg, val);
184         spin_unlock_irqrestore(&chip->reg_lock    196         spin_unlock_irqrestore(&chip->reg_lock, flags);
185         return oldval != reg;                     197         return oldval != reg;
186 }                                                 198 }
187                                                   199 
188                                                   200 
189 #define AWACS_VOLUME(xname, xreg, xshift, xinv    201 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
190 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name =    202 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
191   .info = snd_pmac_awacs_info_volume, \           203   .info = snd_pmac_awacs_info_volume, \
192   .get = snd_pmac_awacs_get_volume, \             204   .get = snd_pmac_awacs_get_volume, \
193   .put = snd_pmac_awacs_put_volume, \             205   .put = snd_pmac_awacs_put_volume, \
194   .private_value = (xreg) | ((xshift) << 8) |     206   .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
195                                                   207 
196 /*                                                208 /*
197  * mute master/ogain for AWACS: mono              209  * mute master/ogain for AWACS: mono
198  */                                               210  */
199 static int snd_pmac_awacs_get_switch(struct sn    211 static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
200                                      struct sn    212                                      struct snd_ctl_elem_value *ucontrol)
201 {                                                 213 {
202         struct snd_pmac *chip = snd_kcontrol_c    214         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
203         int reg = kcontrol->private_value & 0x    215         int reg = kcontrol->private_value & 0xff;
204         int shift = (kcontrol->private_value >    216         int shift = (kcontrol->private_value >> 8) & 0xff;
205         int invert = (kcontrol->private_value     217         int invert = (kcontrol->private_value >> 16) & 1;
206         int val;                                  218         int val;
207         unsigned long flags;                      219         unsigned long flags;
208                                                   220 
209         spin_lock_irqsave(&chip->reg_lock, fla    221         spin_lock_irqsave(&chip->reg_lock, flags);
210         val = (chip->awacs_reg[reg] >> shift)     222         val = (chip->awacs_reg[reg] >> shift) & 1;
211         spin_unlock_irqrestore(&chip->reg_lock    223         spin_unlock_irqrestore(&chip->reg_lock, flags);
212         if (invert)                               224         if (invert)
213                 val = 1 - val;                    225                 val = 1 - val;
214         ucontrol->value.integer.value[0] = val    226         ucontrol->value.integer.value[0] = val;
215         return 0;                                 227         return 0;
216 }                                                 228 }
217                                                   229 
218 static int snd_pmac_awacs_put_switch(struct sn    230 static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
219                                      struct sn    231                                      struct snd_ctl_elem_value *ucontrol)
220 {                                                 232 {
221         struct snd_pmac *chip = snd_kcontrol_c    233         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
222         int reg = kcontrol->private_value & 0x    234         int reg = kcontrol->private_value & 0xff;
223         int shift = (kcontrol->private_value >    235         int shift = (kcontrol->private_value >> 8) & 0xff;
224         int invert = (kcontrol->private_value     236         int invert = (kcontrol->private_value >> 16) & 1;
225         int mask = 1 << shift;                    237         int mask = 1 << shift;
226         int val, changed;                         238         int val, changed;
227         unsigned long flags;                      239         unsigned long flags;
228                                                   240 
229         spin_lock_irqsave(&chip->reg_lock, fla    241         spin_lock_irqsave(&chip->reg_lock, flags);
230         val = chip->awacs_reg[reg] & ~mask;       242         val = chip->awacs_reg[reg] & ~mask;
231         if (ucontrol->value.integer.value[0] !    243         if (ucontrol->value.integer.value[0] != invert)
232                 val |= mask;                      244                 val |= mask;
233         changed = chip->awacs_reg[reg] != val;    245         changed = chip->awacs_reg[reg] != val;
234         if (changed)                              246         if (changed)
235                 snd_pmac_awacs_write_reg(chip,    247                 snd_pmac_awacs_write_reg(chip, reg, val);
236         spin_unlock_irqrestore(&chip->reg_lock    248         spin_unlock_irqrestore(&chip->reg_lock, flags);
237         return changed;                           249         return changed;
238 }                                                 250 }
239                                                   251 
240 #define AWACS_SWITCH(xname, xreg, xshift, xinv    252 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
241 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name =    253 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
242   .info = snd_pmac_boolean_mono_info, \           254   .info = snd_pmac_boolean_mono_info, \
243   .get = snd_pmac_awacs_get_switch, \             255   .get = snd_pmac_awacs_get_switch, \
244   .put = snd_pmac_awacs_put_switch, \             256   .put = snd_pmac_awacs_put_switch, \
245   .private_value = (xreg) | ((xshift) << 8) |     257   .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
246                                                   258 
247                                                   259 
248 #ifdef PMAC_AMP_AVAIL                             260 #ifdef PMAC_AMP_AVAIL
249 /*                                                261 /*
250  * controls for perch/whisper extension cards,    262  * controls for perch/whisper extension cards, e.g. G3 desktop
251  *                                                263  *
252  * TDA7433 connected via i2c address 0x45 (= 0    264  * TDA7433 connected via i2c address 0x45 (= 0x8a),
253  * accessed through cuda                          265  * accessed through cuda
254  */                                               266  */
255 static void awacs_set_cuda(int reg, int val)      267 static void awacs_set_cuda(int reg, int val)
256 {                                                 268 {
257         struct adb_request req;                   269         struct adb_request req;
258         cuda_request(&req, NULL, 5, CUDA_PACKE    270         cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
259                         reg, val);                271                         reg, val);
260         while (! req.complete)                    272         while (! req.complete)
261                 cuda_poll();                      273                 cuda_poll();
262 }                                                 274 }
263                                                   275 
264 /*                                                276 /*
265  * level = 0 - 14, 7 = 0 dB                       277  * level = 0 - 14, 7 = 0 dB
266  */                                               278  */
267 static void awacs_amp_set_tone(struct awacs_am    279 static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
268 {                                                 280 {
269         amp->amp_tone[0] = bass;                  281         amp->amp_tone[0] = bass;
270         amp->amp_tone[1] = treble;                282         amp->amp_tone[1] = treble;
271         if (bass > 7)                             283         if (bass > 7)
272                 bass = (14 - bass) + 8;           284                 bass = (14 - bass) + 8;
273         if (treble > 7)                           285         if (treble > 7)
274                 treble = (14 - treble) + 8;       286                 treble = (14 - treble) + 8;
275         awacs_set_cuda(2, (bass << 4) | treble    287         awacs_set_cuda(2, (bass << 4) | treble);
276 }                                                 288 }
277                                                   289 
278 /*                                                290 /*
279  * vol = 0 - 31 (attenuation), 32 = mute bit,     291  * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
280  */                                               292  */
281 static int awacs_amp_set_vol(struct awacs_amp     293 static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
282                              int lvol, int rvo    294                              int lvol, int rvol, int do_check)
283 {                                                 295 {
284         if (do_check && amp->amp_vol[index][0]    296         if (do_check && amp->amp_vol[index][0] == lvol &&
285                         amp->amp_vol[index][1]    297                         amp->amp_vol[index][1] == rvol)
286                 return 0;                         298                 return 0;
287         awacs_set_cuda(3 + index, lvol);          299         awacs_set_cuda(3 + index, lvol);
288         awacs_set_cuda(5 + index, rvol);          300         awacs_set_cuda(5 + index, rvol);
289         amp->amp_vol[index][0] = lvol;            301         amp->amp_vol[index][0] = lvol;
290         amp->amp_vol[index][1] = rvol;            302         amp->amp_vol[index][1] = rvol;
291         return 1;                                 303         return 1;
292 }                                                 304 }
293                                                   305 
294 /*                                                306 /*
295  * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB             307  * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
296  */                                               308  */
297 static void awacs_amp_set_master(struct awacs_    309 static void awacs_amp_set_master(struct awacs_amp *amp, int vol)
298 {                                                 310 {
299         amp->amp_master = vol;                    311         amp->amp_master = vol;
300         if (vol <= 79)                            312         if (vol <= 79)
301                 vol = 32 + (79 - vol);            313                 vol = 32 + (79 - vol);
302         else                                      314         else
303                 vol = 32 - (vol - 79);            315                 vol = 32 - (vol - 79);
304         awacs_set_cuda(1, vol);                   316         awacs_set_cuda(1, vol);
305 }                                                 317 }
306                                                   318 
307 static void awacs_amp_free(struct snd_pmac *ch    319 static void awacs_amp_free(struct snd_pmac *chip)
308 {                                                 320 {
309         struct awacs_amp *amp = chip->mixer_da    321         struct awacs_amp *amp = chip->mixer_data;
310         if (!amp)                                 322         if (!amp)
311                 return;                           323                 return;
312         kfree(amp);                               324         kfree(amp);
313         chip->mixer_data = NULL;                  325         chip->mixer_data = NULL;
314         chip->mixer_free = NULL;                  326         chip->mixer_free = NULL;
315 }                                                 327 }
316                                                   328 
317                                                   329 
318 /*                                                330 /*
319  * mixer controls                                 331  * mixer controls
320  */                                               332  */
321 static int snd_pmac_awacs_info_volume_amp(stru    333 static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
322                                           stru    334                                           struct snd_ctl_elem_info *uinfo)
323 {                                                 335 {
324         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    336         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
325         uinfo->count = 2;                         337         uinfo->count = 2;
326         uinfo->value.integer.min = 0;             338         uinfo->value.integer.min = 0;
327         uinfo->value.integer.max = 31;            339         uinfo->value.integer.max = 31;
328         return 0;                                 340         return 0;
329 }                                                 341 }
330                                                   342 
331 static int snd_pmac_awacs_get_volume_amp(struc    343 static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
332                                          struc    344                                          struct snd_ctl_elem_value *ucontrol)
333 {                                                 345 {
334         struct snd_pmac *chip = snd_kcontrol_c    346         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
335         int index = kcontrol->private_value;      347         int index = kcontrol->private_value;
336         struct awacs_amp *amp = chip->mixer_da    348         struct awacs_amp *amp = chip->mixer_data;
337                                                   349 
338         ucontrol->value.integer.value[0] = 31     350         ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
339         ucontrol->value.integer.value[1] = 31     351         ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
340         return 0;                                 352         return 0;
341 }                                                 353 }
342                                                   354 
343 static int snd_pmac_awacs_put_volume_amp(struc    355 static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
344                                          struc    356                                          struct snd_ctl_elem_value *ucontrol)
345 {                                                 357 {
346         struct snd_pmac *chip = snd_kcontrol_c    358         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
347         int index = kcontrol->private_value;      359         int index = kcontrol->private_value;
348         int vol[2];                               360         int vol[2];
349         struct awacs_amp *amp = chip->mixer_da    361         struct awacs_amp *amp = chip->mixer_data;
350                                                   362 
351         vol[0] = (31 - (ucontrol->value.intege    363         vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
352                 | (amp->amp_vol[index][0] & 32    364                 | (amp->amp_vol[index][0] & 32);
353         vol[1] = (31 - (ucontrol->value.intege    365         vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
354                 | (amp->amp_vol[index][1] & 32    366                 | (amp->amp_vol[index][1] & 32);
355         return awacs_amp_set_vol(amp, index, v    367         return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
356 }                                                 368 }
357                                                   369 
358 static int snd_pmac_awacs_get_switch_amp(struc    370 static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
359                                          struc    371                                          struct snd_ctl_elem_value *ucontrol)
360 {                                                 372 {
361         struct snd_pmac *chip = snd_kcontrol_c    373         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
362         int index = kcontrol->private_value;      374         int index = kcontrol->private_value;
363         struct awacs_amp *amp = chip->mixer_da    375         struct awacs_amp *amp = chip->mixer_data;
364                                                   376 
365         ucontrol->value.integer.value[0] = (am    377         ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
366                                         ? 0 :     378                                         ? 0 : 1;
367         ucontrol->value.integer.value[1] = (am    379         ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
368                                         ? 0 :     380                                         ? 0 : 1;
369         return 0;                                 381         return 0;
370 }                                                 382 }
371                                                   383 
372 static int snd_pmac_awacs_put_switch_amp(struc    384 static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
373                                          struc    385                                          struct snd_ctl_elem_value *ucontrol)
374 {                                                 386 {
375         struct snd_pmac *chip = snd_kcontrol_c    387         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
376         int index = kcontrol->private_value;      388         int index = kcontrol->private_value;
377         int vol[2];                               389         int vol[2];
378         struct awacs_amp *amp = chip->mixer_da    390         struct awacs_amp *amp = chip->mixer_data;
379                                                   391 
380         vol[0] = (ucontrol->value.integer.valu    392         vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
381                 | (amp->amp_vol[index][0] & 31    393                 | (amp->amp_vol[index][0] & 31);
382         vol[1] = (ucontrol->value.integer.valu    394         vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
383                 | (amp->amp_vol[index][1] & 31    395                 | (amp->amp_vol[index][1] & 31);
384         return awacs_amp_set_vol(amp, index, v    396         return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
385 }                                                 397 }
386                                                   398 
387 static int snd_pmac_awacs_info_tone_amp(struct    399 static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
388                                         struct    400                                         struct snd_ctl_elem_info *uinfo)
389 {                                                 401 {
390         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    402         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
391         uinfo->count = 1;                         403         uinfo->count = 1;
392         uinfo->value.integer.min = 0;             404         uinfo->value.integer.min = 0;
393         uinfo->value.integer.max = 14;            405         uinfo->value.integer.max = 14;
394         return 0;                                 406         return 0;
395 }                                                 407 }
396                                                   408 
397 static int snd_pmac_awacs_get_tone_amp(struct     409 static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
398                                        struct     410                                        struct snd_ctl_elem_value *ucontrol)
399 {                                                 411 {
400         struct snd_pmac *chip = snd_kcontrol_c    412         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
401         int index = kcontrol->private_value;      413         int index = kcontrol->private_value;
402         struct awacs_amp *amp = chip->mixer_da    414         struct awacs_amp *amp = chip->mixer_data;
403                                                   415 
404         ucontrol->value.integer.value[0] = amp    416         ucontrol->value.integer.value[0] = amp->amp_tone[index];
405         return 0;                                 417         return 0;
406 }                                                 418 }
407                                                   419 
408 static int snd_pmac_awacs_put_tone_amp(struct     420 static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
409                                        struct     421                                        struct snd_ctl_elem_value *ucontrol)
410 {                                                 422 {
411         struct snd_pmac *chip = snd_kcontrol_c    423         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
412         int index = kcontrol->private_value;      424         int index = kcontrol->private_value;
413         struct awacs_amp *amp = chip->mixer_da    425         struct awacs_amp *amp = chip->mixer_data;
414         unsigned int val;                         426         unsigned int val;
415                                                   427 
416         val = ucontrol->value.integer.value[0]    428         val = ucontrol->value.integer.value[0];
417         if (val > 14)                             429         if (val > 14)
418                 return -EINVAL;                   430                 return -EINVAL;
419         if (val != amp->amp_tone[index]) {        431         if (val != amp->amp_tone[index]) {
420                 amp->amp_tone[index] = val;       432                 amp->amp_tone[index] = val;
421                 awacs_amp_set_tone(amp, amp->a    433                 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
422                 return 1;                         434                 return 1;
423         }                                         435         }
424         return 0;                                 436         return 0;
425 }                                                 437 }
426                                                   438 
427 static int snd_pmac_awacs_info_master_amp(stru    439 static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
428                                           stru    440                                           struct snd_ctl_elem_info *uinfo)
429 {                                                 441 {
430         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    442         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
431         uinfo->count = 1;                         443         uinfo->count = 1;
432         uinfo->value.integer.min = 0;             444         uinfo->value.integer.min = 0;
433         uinfo->value.integer.max = 99;            445         uinfo->value.integer.max = 99;
434         return 0;                                 446         return 0;
435 }                                                 447 }
436                                                   448 
437 static int snd_pmac_awacs_get_master_amp(struc    449 static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
438                                          struc    450                                          struct snd_ctl_elem_value *ucontrol)
439 {                                                 451 {
440         struct snd_pmac *chip = snd_kcontrol_c    452         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
441         struct awacs_amp *amp = chip->mixer_da    453         struct awacs_amp *amp = chip->mixer_data;
442                                                   454 
443         ucontrol->value.integer.value[0] = amp    455         ucontrol->value.integer.value[0] = amp->amp_master;
444         return 0;                                 456         return 0;
445 }                                                 457 }
446                                                   458 
447 static int snd_pmac_awacs_put_master_amp(struc    459 static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
448                                          struc    460                                          struct snd_ctl_elem_value *ucontrol)
449 {                                                 461 {
450         struct snd_pmac *chip = snd_kcontrol_c    462         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
451         struct awacs_amp *amp = chip->mixer_da    463         struct awacs_amp *amp = chip->mixer_data;
452         unsigned int val;                         464         unsigned int val;
453                                                   465 
454         val = ucontrol->value.integer.value[0]    466         val = ucontrol->value.integer.value[0];
455         if (val > 99)                             467         if (val > 99)
456                 return -EINVAL;                   468                 return -EINVAL;
457         if (val != amp->amp_master) {             469         if (val != amp->amp_master) {
458                 amp->amp_master = val;            470                 amp->amp_master = val;
459                 awacs_amp_set_master(amp, amp-    471                 awacs_amp_set_master(amp, amp->amp_master);
460                 return 1;                         472                 return 1;
461         }                                         473         }
462         return 0;                                 474         return 0;
463 }                                                 475 }
464                                                   476 
465 #define AMP_CH_SPK      0                         477 #define AMP_CH_SPK      0
466 #define AMP_CH_HD       1                         478 #define AMP_CH_HD       1
467                                                   479 
468 static const struct snd_kcontrol_new snd_pmac_ !! 480 static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] = {
469         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    481         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
470           .name = "Speaker Playback Volume",      482           .name = "Speaker Playback Volume",
471           .info = snd_pmac_awacs_info_volume_a    483           .info = snd_pmac_awacs_info_volume_amp,
472           .get = snd_pmac_awacs_get_volume_amp    484           .get = snd_pmac_awacs_get_volume_amp,
473           .put = snd_pmac_awacs_put_volume_amp    485           .put = snd_pmac_awacs_put_volume_amp,
474           .private_value = AMP_CH_SPK,            486           .private_value = AMP_CH_SPK,
475         },                                        487         },
476         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    488         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
477           .name = "Headphone Playback Volume",    489           .name = "Headphone Playback Volume",
478           .info = snd_pmac_awacs_info_volume_a    490           .info = snd_pmac_awacs_info_volume_amp,
479           .get = snd_pmac_awacs_get_volume_amp    491           .get = snd_pmac_awacs_get_volume_amp,
480           .put = snd_pmac_awacs_put_volume_amp    492           .put = snd_pmac_awacs_put_volume_amp,
481           .private_value = AMP_CH_HD,             493           .private_value = AMP_CH_HD,
482         },                                        494         },
483         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    495         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
484           .name = "Tone Control - Bass",          496           .name = "Tone Control - Bass",
485           .info = snd_pmac_awacs_info_tone_amp    497           .info = snd_pmac_awacs_info_tone_amp,
486           .get = snd_pmac_awacs_get_tone_amp,     498           .get = snd_pmac_awacs_get_tone_amp,
487           .put = snd_pmac_awacs_put_tone_amp,     499           .put = snd_pmac_awacs_put_tone_amp,
488           .private_value = 0,                     500           .private_value = 0,
489         },                                        501         },
490         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    502         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
491           .name = "Tone Control - Treble",        503           .name = "Tone Control - Treble",
492           .info = snd_pmac_awacs_info_tone_amp    504           .info = snd_pmac_awacs_info_tone_amp,
493           .get = snd_pmac_awacs_get_tone_amp,     505           .get = snd_pmac_awacs_get_tone_amp,
494           .put = snd_pmac_awacs_put_tone_amp,     506           .put = snd_pmac_awacs_put_tone_amp,
495           .private_value = 1,                     507           .private_value = 1,
496         },                                        508         },
497         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    509         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
498           .name = "Amp Master Playback Volume"    510           .name = "Amp Master Playback Volume",
499           .info = snd_pmac_awacs_info_master_a    511           .info = snd_pmac_awacs_info_master_amp,
500           .get = snd_pmac_awacs_get_master_amp    512           .get = snd_pmac_awacs_get_master_amp,
501           .put = snd_pmac_awacs_put_master_amp    513           .put = snd_pmac_awacs_put_master_amp,
502         },                                        514         },
503 };                                                515 };
504                                                   516 
505 static const struct snd_kcontrol_new snd_pmac_    517 static const struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw = {
506         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,      518         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
507         .name = "Headphone Playback Switch",      519         .name = "Headphone Playback Switch",
508         .info = snd_pmac_boolean_stereo_info,     520         .info = snd_pmac_boolean_stereo_info,
509         .get = snd_pmac_awacs_get_switch_amp,     521         .get = snd_pmac_awacs_get_switch_amp,
510         .put = snd_pmac_awacs_put_switch_amp,     522         .put = snd_pmac_awacs_put_switch_amp,
511         .private_value = AMP_CH_HD,               523         .private_value = AMP_CH_HD,
512 };                                                524 };
513                                                   525 
514 static const struct snd_kcontrol_new snd_pmac_    526 static const struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw = {
515         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,      527         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
516         .name = "Speaker Playback Switch",        528         .name = "Speaker Playback Switch",
517         .info = snd_pmac_boolean_stereo_info,     529         .info = snd_pmac_boolean_stereo_info,
518         .get = snd_pmac_awacs_get_switch_amp,     530         .get = snd_pmac_awacs_get_switch_amp,
519         .put = snd_pmac_awacs_put_switch_amp,     531         .put = snd_pmac_awacs_put_switch_amp,
520         .private_value = AMP_CH_SPK,              532         .private_value = AMP_CH_SPK,
521 };                                                533 };
522                                                   534 
523 #endif /* PMAC_AMP_AVAIL */                       535 #endif /* PMAC_AMP_AVAIL */
524                                                   536 
525                                                   537 
526 /*                                                538 /*
527  * mic boost for screamer                         539  * mic boost for screamer
528  */                                               540  */
529 static int snd_pmac_screamer_mic_boost_info(st    541 static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
530                                             st    542                                             struct snd_ctl_elem_info *uinfo)
531 {                                                 543 {
532         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE    544         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
533         uinfo->count = 1;                         545         uinfo->count = 1;
534         uinfo->value.integer.min = 0;             546         uinfo->value.integer.min = 0;
535         uinfo->value.integer.max = 3;             547         uinfo->value.integer.max = 3;
536         return 0;                                 548         return 0;
537 }                                                 549 }
538                                                   550 
539 static int snd_pmac_screamer_mic_boost_get(str    551 static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
540                                            str    552                                            struct snd_ctl_elem_value *ucontrol)
541 {                                                 553 {
542         struct snd_pmac *chip = snd_kcontrol_c    554         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
543         int val = 0;                              555         int val = 0;
544         unsigned long flags;                      556         unsigned long flags;
545                                                   557 
546         spin_lock_irqsave(&chip->reg_lock, fla    558         spin_lock_irqsave(&chip->reg_lock, flags);
547         if (chip->awacs_reg[6] & MASK_MIC_BOOS    559         if (chip->awacs_reg[6] & MASK_MIC_BOOST)
548                 val |= 2;                         560                 val |= 2;
549         if (chip->awacs_reg[0] & MASK_GAINLINE    561         if (chip->awacs_reg[0] & MASK_GAINLINE)
550                 val |= 1;                         562                 val |= 1;
551         spin_unlock_irqrestore(&chip->reg_lock    563         spin_unlock_irqrestore(&chip->reg_lock, flags);
552         ucontrol->value.integer.value[0] = val    564         ucontrol->value.integer.value[0] = val;
553         return 0;                                 565         return 0;
554 }                                                 566 }
555                                                   567 
556 static int snd_pmac_screamer_mic_boost_put(str    568 static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
557                                            str    569                                            struct snd_ctl_elem_value *ucontrol)
558 {                                                 570 {
559         struct snd_pmac *chip = snd_kcontrol_c    571         struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
560         int changed = 0;                          572         int changed = 0;
561         int val0, val6;                           573         int val0, val6;
562         unsigned long flags;                      574         unsigned long flags;
563                                                   575 
564         spin_lock_irqsave(&chip->reg_lock, fla    576         spin_lock_irqsave(&chip->reg_lock, flags);
565         val0 = chip->awacs_reg[0] & ~MASK_GAIN    577         val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
566         val6 = chip->awacs_reg[6] & ~MASK_MIC_    578         val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
567         if (ucontrol->value.integer.value[0] &    579         if (ucontrol->value.integer.value[0] & 1)
568                 val0 |= MASK_GAINLINE;            580                 val0 |= MASK_GAINLINE;
569         if (ucontrol->value.integer.value[0] &    581         if (ucontrol->value.integer.value[0] & 2)
570                 val6 |= MASK_MIC_BOOST;           582                 val6 |= MASK_MIC_BOOST;
571         if (val0 != chip->awacs_reg[0]) {         583         if (val0 != chip->awacs_reg[0]) {
572                 snd_pmac_awacs_write_reg(chip,    584                 snd_pmac_awacs_write_reg(chip, 0, val0);
573                 changed = 1;                      585                 changed = 1;
574         }                                         586         }
575         if (val6 != chip->awacs_reg[6]) {         587         if (val6 != chip->awacs_reg[6]) {
576                 snd_pmac_awacs_write_reg(chip,    588                 snd_pmac_awacs_write_reg(chip, 6, val6);
577                 changed = 1;                      589                 changed = 1;
578         }                                         590         }
579         spin_unlock_irqrestore(&chip->reg_lock    591         spin_unlock_irqrestore(&chip->reg_lock, flags);
580         return changed;                           592         return changed;
581 }                                                 593 }
582                                                   594 
583 /*                                                595 /*
584  * lists of mixer elements                        596  * lists of mixer elements
585  */                                               597  */
586 static const struct snd_kcontrol_new snd_pmac_ !! 598 static struct snd_kcontrol_new snd_pmac_awacs_mixers[] = {
587         AWACS_SWITCH("Master Capture Switch",     599         AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
588         AWACS_VOLUME("Master Capture Volume",     600         AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
589 /*      AWACS_SWITCH("Unknown Playback Switch"    601 /*      AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
590 };                                                602 };
591                                                   603 
592 static const struct snd_kcontrol_new snd_pmac_ !! 604 static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] = {
593         AWACS_VOLUME("Master Playback Volume",    605         AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
594         AWACS_VOLUME("Play-through Playback Vo    606         AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
595         AWACS_SWITCH("Line Capture Switch", 0,    607         AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
596         AWACS_SWITCH("CD Capture Switch", 0, S    608         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
597 };                                                609 };
598                                                   610 
599 static const struct snd_kcontrol_new snd_pmac_ !! 611 static struct snd_kcontrol_new snd_pmac_screamer_mixers_lo[] = {
600         AWACS_VOLUME("Line out Playback Volume    612         AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
601 };                                                613 };
602                                                   614 
603 static const struct snd_kcontrol_new snd_pmac_ !! 615 static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] = {
604         AWACS_VOLUME("Play-through Playback Vo    616         AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
605         AWACS_SWITCH("CD Capture Switch", 0, S    617         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
606 };                                                618 };
607                                                   619 
608 static const struct snd_kcontrol_new snd_pmac_ !! 620 static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] = {
609         AWACS_VOLUME("Line out Playback Volume    621         AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
610         AWACS_VOLUME("Master Playback Volume",    622         AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
611         AWACS_SWITCH("CD Capture Switch", 0, S    623         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
612         AWACS_SWITCH("Line Capture Switch", 0,    624         AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
613 };                                                625 };
614                                                   626 
615 static const struct snd_kcontrol_new snd_pmac_ !! 627 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] = {
616         AWACS_VOLUME("Line out Playback Volume    628         AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
617         AWACS_SWITCH("CD Capture Switch", 0, S    629         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
618         AWACS_SWITCH("Line Capture Switch", 0,    630         AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
619 };                                                631 };
620                                                   632 
621 static const struct snd_kcontrol_new snd_pmac_ !! 633 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac5500[] = {
622         AWACS_VOLUME("Headphone Playback Volum    634         AWACS_VOLUME("Headphone Playback Volume", 2, 6, 1),
623 };                                                635 };
624                                                   636 
625 static const struct snd_kcontrol_new snd_pmac_ !! 637 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] = {
626         AWACS_VOLUME("Master Playback Volume",    638         AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
627         AWACS_SWITCH("CD Capture Switch", 0, S    639         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
628 };                                                640 };
629                                                   641 
630 /* FIXME: is this correct order?                  642 /* FIXME: is this correct order?
631  * screamer (powerbook G3 pismo) seems to have    643  * screamer (powerbook G3 pismo) seems to have different bits...
632  */                                               644  */
633 static const struct snd_kcontrol_new snd_pmac_ !! 645 static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] = {
634         AWACS_SWITCH("Line Capture Switch", 0,    646         AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
635         AWACS_SWITCH("Mic Capture Switch", 0,     647         AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
636 };                                                648 };
637                                                   649 
638 static const struct snd_kcontrol_new snd_pmac_ !! 650 static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] = {
639         AWACS_SWITCH("Line Capture Switch", 0,    651         AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
640         AWACS_SWITCH("Mic Capture Switch", 0,     652         AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
641 };                                                653 };
642                                                   654 
643 static const struct snd_kcontrol_new snd_pmac_ !! 655 static struct snd_kcontrol_new snd_pmac_awacs_mixers2_pmac5500[] = {
644         AWACS_SWITCH("CD Capture Switch", 0, S    656         AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
645 };                                                657 };
646                                                   658 
647 static const struct snd_kcontrol_new snd_pmac_ !! 659 static struct snd_kcontrol_new snd_pmac_awacs_master_sw =
648 AWACS_SWITCH("Master Playback Switch", 1, SHIF    660 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
649                                                   661 
650 static const struct snd_kcontrol_new snd_pmac_ !! 662 static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac =
651 AWACS_SWITCH("Line out Playback Switch", 1, SH    663 AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
652                                                   664 
653 static const struct snd_kcontrol_new snd_pmac_ !! 665 static struct snd_kcontrol_new snd_pmac_awacs_master_sw_pmac5500 =
654 AWACS_SWITCH("Headphone Playback Switch", 1, S    666 AWACS_SWITCH("Headphone Playback Switch", 1, SHIFT_HDMUTE, 1);
655                                                   667 
656 static const struct snd_kcontrol_new snd_pmac_ !! 668 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] = {
657         AWACS_SWITCH("Mic Boost Capture Switch    669         AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
658 };                                                670 };
659                                                   671 
660 static const struct snd_kcontrol_new snd_pmac_ !! 672 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] = {
661         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    673         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
662           .name = "Mic Boost Capture Volume",     674           .name = "Mic Boost Capture Volume",
663           .info = snd_pmac_screamer_mic_boost_    675           .info = snd_pmac_screamer_mic_boost_info,
664           .get = snd_pmac_screamer_mic_boost_g    676           .get = snd_pmac_screamer_mic_boost_get,
665           .put = snd_pmac_screamer_mic_boost_p    677           .put = snd_pmac_screamer_mic_boost_put,
666         },                                        678         },
667 };                                                679 };
668                                                   680 
669 static const struct snd_kcontrol_new snd_pmac_ !! 681 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] =
670 {                                                 682 {
671         AWACS_SWITCH("Line Boost Capture Switc    683         AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
672 };                                                684 };
673                                                   685 
674 static const struct snd_kcontrol_new snd_pmac_ !! 686 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] =
675 {                                                 687 {
676         AWACS_SWITCH("Line Boost Capture Switc    688         AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
677         AWACS_SWITCH("CD Boost Capture Switch"    689         AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
678 };                                                690 };
679                                                   691 
680 static const struct snd_kcontrol_new snd_pmac_ !! 692 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] =
681 {                                                 693 {
682         AWACS_SWITCH("Line Boost Capture Switc    694         AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
683         AWACS_SWITCH("Mic Boost Capture Switch    695         AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
684 };                                                696 };
685                                                   697 
686 static const struct snd_kcontrol_new snd_pmac_ !! 698 static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] = {
687         AWACS_VOLUME("Speaker Playback Volume"    699         AWACS_VOLUME("Speaker Playback Volume", 4, 6, 1),
688 };                                                700 };
689                                                   701 
690 static const struct snd_kcontrol_new snd_pmac_ !! 702 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw =
691 AWACS_SWITCH("Speaker Playback Switch", 1, SHI    703 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
692                                                   704 
693 static const struct snd_kcontrol_new snd_pmac_ !! 705 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 =
694 AWACS_SWITCH("Speaker Playback Switch", 1, SHI    706 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
695                                                   707 
696 static const struct snd_kcontrol_new snd_pmac_ !! 708 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 =
697 AWACS_SWITCH("Speaker Playback Switch", 1, SHI    709 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
698                                                   710 
699                                                   711 
700 /*                                                712 /*
701  * add new mixer elements to the card             713  * add new mixer elements to the card
702  */                                               714  */
703 static int build_mixers(struct snd_pmac *chip,    715 static int build_mixers(struct snd_pmac *chip, int nums,
704                         const struct snd_kcont !! 716                         struct snd_kcontrol_new *mixers)
705 {                                                 717 {
706         int i, err;                               718         int i, err;
707                                                   719 
708         for (i = 0; i < nums; i++) {              720         for (i = 0; i < nums; i++) {
709                 err = snd_ctl_add(chip->card,     721                 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
710                 if (err < 0)                      722                 if (err < 0)
711                         return err;               723                         return err;
712         }                                         724         }
713         return 0;                                 725         return 0;
714 }                                                 726 }
715                                                   727 
716                                                   728 
717 /*                                                729 /*
718  * restore all registers                          730  * restore all registers
719  */                                               731  */
720 static void awacs_restore_all_regs(struct snd_    732 static void awacs_restore_all_regs(struct snd_pmac *chip)
721 {                                                 733 {
722         snd_pmac_awacs_write_noreg(chip, 0, ch    734         snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
723         snd_pmac_awacs_write_noreg(chip, 1, ch    735         snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
724         snd_pmac_awacs_write_noreg(chip, 2, ch    736         snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
725         snd_pmac_awacs_write_noreg(chip, 4, ch    737         snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
726         if (chip->model == PMAC_SCREAMER) {       738         if (chip->model == PMAC_SCREAMER) {
727                 snd_pmac_awacs_write_noreg(chi    739                 snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
728                 snd_pmac_awacs_write_noreg(chi    740                 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
729                 snd_pmac_awacs_write_noreg(chi    741                 snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
730         }                                         742         }
731 }                                                 743 }
732                                                   744 
733 #ifdef CONFIG_PM                                  745 #ifdef CONFIG_PM
734 static void snd_pmac_awacs_suspend(struct snd_    746 static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
735 {                                                 747 {
736         snd_pmac_awacs_write_noreg(chip, 1, (c    748         snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
737                                              |    749                                              | MASK_AMUTE | MASK_CMUTE));
738 }                                                 750 }
739                                                   751 
740 static void snd_pmac_awacs_resume(struct snd_p    752 static void snd_pmac_awacs_resume(struct snd_pmac *chip)
741 {                                                 753 {
742         if (of_machine_is_compatible("PowerBoo    754         if (of_machine_is_compatible("PowerBook3,1")
743             || of_machine_is_compatible("Power    755             || of_machine_is_compatible("PowerBook3,2")) {
744                 msleep(100);                      756                 msleep(100);
745                 snd_pmac_awacs_write_reg(chip,    757                 snd_pmac_awacs_write_reg(chip, 1,
746                         chip->awacs_reg[1] & ~    758                         chip->awacs_reg[1] & ~MASK_PAROUT);
747                 msleep(300);                      759                 msleep(300);
748         }                                         760         }
749                                                   761 
750         awacs_restore_all_regs(chip);             762         awacs_restore_all_regs(chip);
751         if (chip->model == PMAC_SCREAMER) {       763         if (chip->model == PMAC_SCREAMER) {
752                 /* reset power bits in reg 6 *    764                 /* reset power bits in reg 6 */
753                 mdelay(5);                        765                 mdelay(5);
754                 snd_pmac_awacs_write_noreg(chi    766                 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
755         }                                         767         }
756         screamer_recalibrate(chip);               768         screamer_recalibrate(chip);
757 #ifdef PMAC_AMP_AVAIL                             769 #ifdef PMAC_AMP_AVAIL
758         if (chip->mixer_data) {                   770         if (chip->mixer_data) {
759                 struct awacs_amp *amp = chip->    771                 struct awacs_amp *amp = chip->mixer_data;
760                 awacs_amp_set_vol(amp, 0,         772                 awacs_amp_set_vol(amp, 0,
761                                   amp->amp_vol    773                                   amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
762                 awacs_amp_set_vol(amp, 1,         774                 awacs_amp_set_vol(amp, 1,
763                                   amp->amp_vol    775                                   amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
764                 awacs_amp_set_tone(amp, amp->a    776                 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
765                 awacs_amp_set_master(amp, amp-    777                 awacs_amp_set_master(amp, amp->amp_master);
766         }                                         778         }
767 #endif                                            779 #endif
768 }                                                 780 }
769 #endif /* CONFIG_PM */                            781 #endif /* CONFIG_PM */
770                                                   782 
771 #define IS_PM7500 (of_machine_is_compatible("A    783 #define IS_PM7500 (of_machine_is_compatible("AAPL,7500") \
772                 || of_machine_is_compatible("A    784                 || of_machine_is_compatible("AAPL,8500") \
773                 || of_machine_is_compatible("A    785                 || of_machine_is_compatible("AAPL,9500"))
774 #define IS_PM5500 (of_machine_is_compatible("A    786 #define IS_PM5500 (of_machine_is_compatible("AAPL,e411"))
775 #define IS_BEIGE (of_machine_is_compatible("AA    787 #define IS_BEIGE (of_machine_is_compatible("AAPL,Gossamer"))
776 #define IS_IMAC1 (of_machine_is_compatible("Po    788 #define IS_IMAC1 (of_machine_is_compatible("PowerMac2,1"))
777 #define IS_IMAC2 (of_machine_is_compatible("Po    789 #define IS_IMAC2 (of_machine_is_compatible("PowerMac2,2") \
778                 || of_machine_is_compatible("P    790                 || of_machine_is_compatible("PowerMac4,1"))
779 #define IS_G4AGP (of_machine_is_compatible("Po    791 #define IS_G4AGP (of_machine_is_compatible("PowerMac3,1"))
780 #define IS_LOMBARD (of_machine_is_compatible("    792 #define IS_LOMBARD (of_machine_is_compatible("PowerBook1,1"))
781                                                   793 
782 static int imac1, imac2;                          794 static int imac1, imac2;
783                                                   795 
784 #ifdef PMAC_SUPPORT_AUTOMUTE                      796 #ifdef PMAC_SUPPORT_AUTOMUTE
785 /*                                                797 /*
786  * auto-mute stuffs                               798  * auto-mute stuffs
787  */                                               799  */
788 static int snd_pmac_awacs_detect_headphone(str    800 static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
789 {                                                 801 {
790         return (in_le32(&chip->awacs->codec_st    802         return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
791 }                                                 803 }
792                                                   804 
793 #ifdef PMAC_AMP_AVAIL                             805 #ifdef PMAC_AMP_AVAIL
794 static int toggle_amp_mute(struct awacs_amp *a    806 static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
795 {                                                 807 {
796         int vol[2];                               808         int vol[2];
797         vol[0] = amp->amp_vol[index][0] & 31;     809         vol[0] = amp->amp_vol[index][0] & 31;
798         vol[1] = amp->amp_vol[index][1] & 31;     810         vol[1] = amp->amp_vol[index][1] & 31;
799         if (mute) {                               811         if (mute) {
800                 vol[0] |= 32;                     812                 vol[0] |= 32;
801                 vol[1] |= 32;                     813                 vol[1] |= 32;
802         }                                         814         }
803         return awacs_amp_set_vol(amp, index, v    815         return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
804 }                                                 816 }
805 #endif                                            817 #endif
806                                                   818 
807 static void snd_pmac_awacs_update_automute(str    819 static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
808 {                                                 820 {
809         if (chip->auto_mute) {                    821         if (chip->auto_mute) {
810 #ifdef PMAC_AMP_AVAIL                             822 #ifdef PMAC_AMP_AVAIL
811                 if (chip->mixer_data) {           823                 if (chip->mixer_data) {
812                         struct awacs_amp *amp     824                         struct awacs_amp *amp = chip->mixer_data;
813                         int changed;              825                         int changed;
814                         if (snd_pmac_awacs_det    826                         if (snd_pmac_awacs_detect_headphone(chip)) {
815                                 changed = togg    827                                 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
816                                 changed |= tog    828                                 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
817                         } else {                  829                         } else {
818                                 changed = togg    830                                 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
819                                 changed |= tog    831                                 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
820                         }                         832                         }
821                         if (do_notify && ! cha    833                         if (do_notify && ! changed)
822                                 return;           834                                 return;
823                 } else                            835                 } else
824 #endif                                            836 #endif
825                 {                                 837                 {
826                         int reg = chip->awacs_    838                         int reg = chip->awacs_reg[1]
827                                 | (MASK_HDMUTE    839                                 | (MASK_HDMUTE | MASK_SPKMUTE);
828                         if (imac1) {              840                         if (imac1) {
829                                 reg &= ~MASK_S    841                                 reg &= ~MASK_SPKMUTE;
830                                 reg |= MASK_PA    842                                 reg |= MASK_PAROUT1;
831                         } else if (imac2) {       843                         } else if (imac2) {
832                                 reg &= ~MASK_S    844                                 reg &= ~MASK_SPKMUTE;
833                                 reg &= ~MASK_P    845                                 reg &= ~MASK_PAROUT1;
834                         }                         846                         }
835                         if (snd_pmac_awacs_det    847                         if (snd_pmac_awacs_detect_headphone(chip))
836                                 reg &= ~MASK_H    848                                 reg &= ~MASK_HDMUTE;
837                         else if (imac1)           849                         else if (imac1)
838                                 reg &= ~MASK_P    850                                 reg &= ~MASK_PAROUT1;
839                         else if (imac2)           851                         else if (imac2)
840                                 reg |= MASK_PA    852                                 reg |= MASK_PAROUT1;
841                         else                      853                         else
842                                 reg &= ~MASK_S    854                                 reg &= ~MASK_SPKMUTE;
843                         if (do_notify && reg =    855                         if (do_notify && reg == chip->awacs_reg[1])
844                                 return;           856                                 return;
845                         snd_pmac_awacs_write_r    857                         snd_pmac_awacs_write_reg(chip, 1, reg);
846                 }                                 858                 }
847                 if (do_notify) {                  859                 if (do_notify) {
848                         snd_ctl_notify(chip->c    860                         snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
849                                        &chip->    861                                        &chip->master_sw_ctl->id);
850                         snd_ctl_notify(chip->c    862                         snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
851                                        &chip->    863                                        &chip->speaker_sw_ctl->id);
852                         snd_ctl_notify(chip->c    864                         snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
853                                        &chip->    865                                        &chip->hp_detect_ctl->id);
854                 }                                 866                 }
855         }                                         867         }
856 }                                                 868 }
857 #endif /* PMAC_SUPPORT_AUTOMUTE */                869 #endif /* PMAC_SUPPORT_AUTOMUTE */
858                                                   870 
859                                                   871 
860 /*                                                872 /*
861  * initialize chip                                873  * initialize chip
862  */                                               874  */
863 int                                               875 int
864 snd_pmac_awacs_init(struct snd_pmac *chip)        876 snd_pmac_awacs_init(struct snd_pmac *chip)
865 {                                                 877 {
866         int pm7500 = IS_PM7500;                   878         int pm7500 = IS_PM7500;
867         int pm5500 = IS_PM5500;                   879         int pm5500 = IS_PM5500;
868         int beige = IS_BEIGE;                     880         int beige = IS_BEIGE;
869         int g4agp = IS_G4AGP;                     881         int g4agp = IS_G4AGP;
870         int lombard = IS_LOMBARD;                 882         int lombard = IS_LOMBARD;
871         int imac;                                 883         int imac;
872         int err, vol;                             884         int err, vol;
873         struct snd_kcontrol *vmaster_sw, *vmas    885         struct snd_kcontrol *vmaster_sw, *vmaster_vol;
874         struct snd_kcontrol *master_vol, *spea    886         struct snd_kcontrol *master_vol, *speaker_vol;
875                                                   887 
876         imac1 = IS_IMAC1;                         888         imac1 = IS_IMAC1;
877         imac2 = IS_IMAC2;                         889         imac2 = IS_IMAC2;
878         imac = imac1 || imac2;                    890         imac = imac1 || imac2;
879         /* looks like MASK_GAINLINE triggers s    891         /* looks like MASK_GAINLINE triggers something, so we set here
880          * as start-up                            892          * as start-up
881          */                                       893          */
882         chip->awacs_reg[0] = MASK_MUX_CD | 0xf    894         chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
883         chip->awacs_reg[1] = MASK_CMUTE | MASK    895         chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
884         /* FIXME: Only machines with external     896         /* FIXME: Only machines with external SRS module need MASK_PAROUT */
885         if (chip->has_iic || chip->device_id =    897         if (chip->has_iic || chip->device_id == 0x5 ||
886             /* chip->_device_id == 0x8 || */      898             /* chip->_device_id == 0x8 || */
887             chip->device_id == 0xb)               899             chip->device_id == 0xb)
888                 chip->awacs_reg[1] |= MASK_PAR    900                 chip->awacs_reg[1] |= MASK_PAROUT;
889         /* get default volume from nvram */       901         /* get default volume from nvram */
890         // vol = (~nvram_read_byte(0x1308) & 7    902         // vol = (~nvram_read_byte(0x1308) & 7) << 1;
891         // vol = ((pmac_xpram_read( 8 ) & 7 )     903         // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
892         vol = 0x0f; /* no, on alsa, muted as d    904         vol = 0x0f; /* no, on alsa, muted as default */
893         vol = vol + (vol << 6);                   905         vol = vol + (vol << 6);
894         chip->awacs_reg[2] = vol;                 906         chip->awacs_reg[2] = vol;
895         chip->awacs_reg[4] = vol;                 907         chip->awacs_reg[4] = vol;
896         if (chip->model == PMAC_SCREAMER) {       908         if (chip->model == PMAC_SCREAMER) {
897                 /* FIXME: screamer has loopthr    909                 /* FIXME: screamer has loopthru vol control */
898                 chip->awacs_reg[5] = vol;         910                 chip->awacs_reg[5] = vol;
899                 /* FIXME: maybe should be vol     911                 /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
900                 chip->awacs_reg[6] = MASK_MIC_    912                 chip->awacs_reg[6] = MASK_MIC_BOOST;
901                 chip->awacs_reg[7] = 0;           913                 chip->awacs_reg[7] = 0;
902         }                                         914         }
903                                                   915 
904         awacs_restore_all_regs(chip);             916         awacs_restore_all_regs(chip);
905         chip->manufacturer = (in_le32(&chip->a    917         chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
906         screamer_recalibrate(chip);               918         screamer_recalibrate(chip);
907                                                   919 
908         chip->revision = (in_le32(&chip->awacs    920         chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
909 #ifdef PMAC_AMP_AVAIL                             921 #ifdef PMAC_AMP_AVAIL
910         if (chip->revision == 3 && chip->has_i    922         if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
911                 struct awacs_amp *amp = kzallo    923                 struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
912                 if (! amp)                        924                 if (! amp)
913                         return -ENOMEM;           925                         return -ENOMEM;
914                 chip->mixer_data = amp;           926                 chip->mixer_data = amp;
915                 chip->mixer_free = awacs_amp_f    927                 chip->mixer_free = awacs_amp_free;
916                 /* mute and zero vol */           928                 /* mute and zero vol */
917                 awacs_amp_set_vol(amp, 0, 63,     929                 awacs_amp_set_vol(amp, 0, 63, 63, 0);
918                 awacs_amp_set_vol(amp, 1, 63,     930                 awacs_amp_set_vol(amp, 1, 63, 63, 0);
919                 awacs_amp_set_tone(amp, 7, 7);    931                 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
920                 awacs_amp_set_master(amp, 79);    932                 awacs_amp_set_master(amp, 79); /* 0 dB */
921         }                                         933         }
922 #endif /* PMAC_AMP_AVAIL */                       934 #endif /* PMAC_AMP_AVAIL */
923                                                   935 
924         if (chip->hp_stat_mask == 0) {            936         if (chip->hp_stat_mask == 0) {
925                 /* set headphone-jack detectio    937                 /* set headphone-jack detection bit */
926                 switch (chip->model) {            938                 switch (chip->model) {
927                 case PMAC_AWACS:                  939                 case PMAC_AWACS:
928                         chip->hp_stat_mask = p    940                         chip->hp_stat_mask = pm7500 || pm5500 ? MASK_HDPCONN
929                                 : MASK_LOCONN;    941                                 : MASK_LOCONN;
930                         break;                    942                         break;
931                 case PMAC_SCREAMER:               943                 case PMAC_SCREAMER:
932                         switch (chip->device_i    944                         switch (chip->device_id) {
933                         case 0x08:                945                         case 0x08:
934                         case 0x0B:                946                         case 0x0B:
935                                 chip->hp_stat_    947                                 chip->hp_stat_mask = imac
936                                         ? MASK    948                                         ? MASK_LOCONN_IMAC |
937                                         MASK_H    949                                         MASK_HDPLCONN_IMAC |
938                                         MASK_H    950                                         MASK_HDPRCONN_IMAC
939                                         : MASK    951                                         : MASK_HDPCONN;
940                                 break;            952                                 break;
941                         case 0x00:                953                         case 0x00:
942                         case 0x05:                954                         case 0x05:
943                                 chip->hp_stat_    955                                 chip->hp_stat_mask = MASK_LOCONN;
944                                 break;            956                                 break;
945                         default:                  957                         default:
946                                 chip->hp_stat_    958                                 chip->hp_stat_mask = MASK_HDPCONN;
947                                 break;            959                                 break;
948                         }                         960                         }
949                         break;                    961                         break;
950                 default:                          962                 default:
951                         snd_BUG();                963                         snd_BUG();
952                         break;                    964                         break;
953                 }                                 965                 }
954         }                                         966         }
955                                                   967 
956         /*                                        968         /*
957          * build mixers                           969          * build mixers
958          */                                       970          */
959         strcpy(chip->card->mixername, "PowerMa    971         strcpy(chip->card->mixername, "PowerMac AWACS");
960                                                   972 
961         err = build_mixers(chip, ARRAY_SIZE(sn    973         err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
962                                 snd_pmac_awacs    974                                 snd_pmac_awacs_mixers);
963         if (err < 0)                              975         if (err < 0)
964                 return err;                       976                 return err;
965         if (beige || g4agp)                       977         if (beige || g4agp)
966                 ;                                 978                 ;
967         else if (chip->model == PMAC_SCREAMER     979         else if (chip->model == PMAC_SCREAMER || pm5500)
968                 err = build_mixers(chip, ARRAY    980                 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
969                                    snd_pmac_sc    981                                    snd_pmac_screamer_mixers2);
970         else if (!pm7500)                         982         else if (!pm7500)
971                 err = build_mixers(chip, ARRAY    983                 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
972                                    snd_pmac_aw    984                                    snd_pmac_awacs_mixers2);
973         if (err < 0)                              985         if (err < 0)
974                 return err;                       986                 return err;
975         if (pm5500) {                             987         if (pm5500) {
976                 err = build_mixers(chip,          988                 err = build_mixers(chip,
977                                    ARRAY_SIZE(    989                                    ARRAY_SIZE(snd_pmac_awacs_mixers2_pmac5500),
978                                    snd_pmac_aw    990                                    snd_pmac_awacs_mixers2_pmac5500);
979                 if (err < 0)                      991                 if (err < 0)
980                         return err;               992                         return err;
981         }                                         993         }
982         master_vol = NULL;                        994         master_vol = NULL;
983         if (pm7500)                               995         if (pm7500)
984                 err = build_mixers(chip,          996                 err = build_mixers(chip,
985                                    ARRAY_SIZE(    997                                    ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
986                                    snd_pmac_aw    998                                    snd_pmac_awacs_mixers_pmac7500);
987         else if (pm5500)                          999         else if (pm5500)
988                 err = snd_ctl_add(chip->card,     1000                 err = snd_ctl_add(chip->card,
989                     (master_vol = snd_ctl_new1    1001                     (master_vol = snd_ctl_new1(snd_pmac_awacs_mixers_pmac5500,
990                                                   1002                                                 chip)));
991         else if (beige)                           1003         else if (beige)
992                 err = build_mixers(chip,          1004                 err = build_mixers(chip,
993                                    ARRAY_SIZE(    1005                                    ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
994                                    snd_pmac_sc    1006                                    snd_pmac_screamer_mixers_beige);
995         else if (imac || lombard) {               1007         else if (imac || lombard) {
996                 err = snd_ctl_add(chip->card,     1008                 err = snd_ctl_add(chip->card,
997                     (master_vol = snd_ctl_new1    1009                     (master_vol = snd_ctl_new1(snd_pmac_screamer_mixers_lo,
998                                                   1010                                                 chip)));
999                 if (err < 0)                      1011                 if (err < 0)
1000                         return err;              1012                         return err;
1001                 err = build_mixers(chip,         1013                 err = build_mixers(chip,
1002                                    ARRAY_SIZE    1014                                    ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
1003                                    snd_pmac_s    1015                                    snd_pmac_screamer_mixers_imac);
1004         } else if (g4agp)                        1016         } else if (g4agp)
1005                 err = build_mixers(chip,         1017                 err = build_mixers(chip,
1006                                    ARRAY_SIZE    1018                                    ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
1007                                    snd_pmac_s    1019                                    snd_pmac_screamer_mixers_g4agp);
1008         else                                     1020         else
1009                 err = build_mixers(chip,         1021                 err = build_mixers(chip,
1010                                    ARRAY_SIZE    1022                                    ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
1011                                    snd_pmac_a    1023                                    snd_pmac_awacs_mixers_pmac);
1012         if (err < 0)                             1024         if (err < 0)
1013                 return err;                      1025                 return err;
1014         chip->master_sw_ctl = snd_ctl_new1((p    1026         chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp || lombard)
1015                         ? &snd_pmac_awacs_mas    1027                         ? &snd_pmac_awacs_master_sw_imac
1016                         : pm5500                 1028                         : pm5500
1017                         ? &snd_pmac_awacs_mas    1029                         ? &snd_pmac_awacs_master_sw_pmac5500
1018                         : &snd_pmac_awacs_mas    1030                         : &snd_pmac_awacs_master_sw, chip);
1019         err = snd_ctl_add(chip->card, chip->m    1031         err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1020         if (err < 0)                             1032         if (err < 0)
1021                 return err;                      1033                 return err;
1022 #ifdef PMAC_AMP_AVAIL                            1034 #ifdef PMAC_AMP_AVAIL
1023         if (chip->mixer_data) {                  1035         if (chip->mixer_data) {
1024                 /* use amplifier.  the signal    1036                 /* use amplifier.  the signal is connected from route A
1025                  * to the amp.  the amp has i    1037                  * to the amp.  the amp has its headphone and speaker
1026                  * volumes and mute switches,    1038                  * volumes and mute switches, so we use them instead of
1027                  * screamer registers.           1039                  * screamer registers.
1028                  * in this case, it seems the    1040                  * in this case, it seems the route C is not used.
1029                  */                              1041                  */
1030                 err = build_mixers(chip, ARRA    1042                 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
1031                                         snd_p    1043                                         snd_pmac_awacs_amp_vol);
1032                 if (err < 0)                     1044                 if (err < 0)
1033                         return err;              1045                         return err;
1034                 /* overwrite */                  1046                 /* overwrite */
1035                 chip->master_sw_ctl = snd_ctl    1047                 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
1036                                                  1048                                                         chip);
1037                 err = snd_ctl_add(chip->card,    1049                 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1038                 if (err < 0)                     1050                 if (err < 0)
1039                         return err;              1051                         return err;
1040                 chip->speaker_sw_ctl = snd_ct    1052                 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
1041                                                  1053                                                         chip);
1042                 err = snd_ctl_add(chip->card,    1054                 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1043                 if (err < 0)                     1055                 if (err < 0)
1044                         return err;              1056                         return err;
1045         } else                                   1057         } else
1046 #endif /* PMAC_AMP_AVAIL */                      1058 #endif /* PMAC_AMP_AVAIL */
1047         {                                        1059         {
1048                 /* route A = headphone, route    1060                 /* route A = headphone, route C = speaker */
1049                 err = snd_ctl_add(chip->card,    1061                 err = snd_ctl_add(chip->card,
1050                     (speaker_vol = snd_ctl_ne    1062                     (speaker_vol = snd_ctl_new1(snd_pmac_awacs_speaker_vol,
1051                                                  1063                                                 chip)));
1052                 if (err < 0)                     1064                 if (err < 0)
1053                         return err;              1065                         return err;
1054                 chip->speaker_sw_ctl = snd_ct    1066                 chip->speaker_sw_ctl = snd_ctl_new1(imac1
1055                                 ? &snd_pmac_a    1067                                 ? &snd_pmac_awacs_speaker_sw_imac1
1056                                 : imac2          1068                                 : imac2
1057                                 ? &snd_pmac_a    1069                                 ? &snd_pmac_awacs_speaker_sw_imac2
1058                                 : &snd_pmac_a    1070                                 : &snd_pmac_awacs_speaker_sw, chip);
1059                 err = snd_ctl_add(chip->card,    1071                 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1060                 if (err < 0)                     1072                 if (err < 0)
1061                         return err;              1073                         return err;
1062         }                                        1074         }
1063                                                  1075 
1064         if (pm5500 || imac || lombard) {         1076         if (pm5500 || imac || lombard) {
1065                 vmaster_sw = snd_ctl_make_vir    1077                 vmaster_sw = snd_ctl_make_virtual_master(
1066                         "Master Playback Swit    1078                         "Master Playback Switch", (unsigned int *) NULL);
1067                 err = snd_ctl_add_follower_un !! 1079                 err = snd_ctl_add_slave_uncached(vmaster_sw,
1068                                               !! 1080                                                  chip->master_sw_ctl);
1069                 if (err < 0)                     1081                 if (err < 0)
1070                         return err;              1082                         return err;
1071                 err = snd_ctl_add_follower_un !! 1083                 err = snd_ctl_add_slave_uncached(vmaster_sw,
1072                                               !! 1084                                                   chip->speaker_sw_ctl);
1073                 if (err < 0)                     1085                 if (err < 0)
1074                         return err;              1086                         return err;
1075                 err = snd_ctl_add(chip->card,    1087                 err = snd_ctl_add(chip->card, vmaster_sw);
1076                 if (err < 0)                     1088                 if (err < 0)
1077                         return err;              1089                         return err;
1078                 vmaster_vol = snd_ctl_make_vi    1090                 vmaster_vol = snd_ctl_make_virtual_master(
1079                         "Master Playback Volu    1091                         "Master Playback Volume", (unsigned int *) NULL);
1080                 err = snd_ctl_add_follower(vm !! 1092                 err = snd_ctl_add_slave(vmaster_vol, master_vol);
1081                 if (err < 0)                     1093                 if (err < 0)
1082                         return err;              1094                         return err;
1083                 err = snd_ctl_add_follower(vm !! 1095                 err = snd_ctl_add_slave(vmaster_vol, speaker_vol);
1084                 if (err < 0)                     1096                 if (err < 0)
1085                         return err;              1097                         return err;
1086                 err = snd_ctl_add(chip->card,    1098                 err = snd_ctl_add(chip->card, vmaster_vol);
1087                 if (err < 0)                     1099                 if (err < 0)
1088                         return err;              1100                         return err;
1089         }                                        1101         }
1090                                                  1102 
1091         if (beige || g4agp)                      1103         if (beige || g4agp)
1092                 err = build_mixers(chip,         1104                 err = build_mixers(chip,
1093                                 ARRAY_SIZE(sn    1105                                 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
1094                                 snd_pmac_scre    1106                                 snd_pmac_screamer_mic_boost_beige);
1095         else if (imac)                           1107         else if (imac)
1096                 err = build_mixers(chip,         1108                 err = build_mixers(chip,
1097                                 ARRAY_SIZE(sn    1109                                 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
1098                                 snd_pmac_scre    1110                                 snd_pmac_screamer_mic_boost_imac);
1099         else if (chip->model == PMAC_SCREAMER    1111         else if (chip->model == PMAC_SCREAMER)
1100                 err = build_mixers(chip,         1112                 err = build_mixers(chip,
1101                                 ARRAY_SIZE(sn    1113                                 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1102                                 snd_pmac_scre    1114                                 snd_pmac_screamer_mic_boost);
1103         else if (pm7500)                         1115         else if (pm7500)
1104                 err = build_mixers(chip,         1116                 err = build_mixers(chip,
1105                                 ARRAY_SIZE(sn    1117                                 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1106                                 snd_pmac_awac    1118                                 snd_pmac_awacs_mic_boost_pmac7500);
1107         else                                     1119         else
1108                 err = build_mixers(chip, ARRA    1120                 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1109                                 snd_pmac_awac    1121                                 snd_pmac_awacs_mic_boost);
1110         if (err < 0)                             1122         if (err < 0)
1111                 return err;                      1123                 return err;
1112                                                  1124 
1113         /*                                       1125         /*
1114          * set lowlevel callbacks                1126          * set lowlevel callbacks
1115          */                                      1127          */
1116         chip->set_format = snd_pmac_awacs_set    1128         chip->set_format = snd_pmac_awacs_set_format;
1117 #ifdef CONFIG_PM                                 1129 #ifdef CONFIG_PM
1118         chip->suspend = snd_pmac_awacs_suspen    1130         chip->suspend = snd_pmac_awacs_suspend;
1119         chip->resume = snd_pmac_awacs_resume;    1131         chip->resume = snd_pmac_awacs_resume;
1120 #endif                                           1132 #endif
1121 #ifdef PMAC_SUPPORT_AUTOMUTE                     1133 #ifdef PMAC_SUPPORT_AUTOMUTE
1122         err = snd_pmac_add_automute(chip);       1134         err = snd_pmac_add_automute(chip);
1123         if (err < 0)                             1135         if (err < 0)
1124                 return err;                      1136                 return err;
1125         chip->detect_headphone = snd_pmac_awa    1137         chip->detect_headphone = snd_pmac_awacs_detect_headphone;
1126         chip->update_automute = snd_pmac_awac    1138         chip->update_automute = snd_pmac_awacs_update_automute;
1127         snd_pmac_awacs_update_automute(chip,     1139         snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
1128 #endif                                           1140 #endif
1129         if (chip->model == PMAC_SCREAMER) {      1141         if (chip->model == PMAC_SCREAMER) {
1130                 snd_pmac_awacs_write_noreg(ch    1142                 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
1131                 snd_pmac_awacs_write_noreg(ch    1143                 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
1132         }                                        1144         }
1133                                                  1145 
1134         return 0;                                1146         return 0;
1135 }                                                1147 }
1136                                                  1148 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php