awacs.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*
  2. * PMac AWACS lowlevel functions
  3. *
  4. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  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
  20. */
  21. #include <asm/io.h>
  22. #include <asm/nvram.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <sound/core.h>
  27. #include "pmac.h"
  28. #ifdef CONFIG_ADB_CUDA
  29. #define PMAC_AMP_AVAIL
  30. #endif
  31. #ifdef PMAC_AMP_AVAIL
  32. struct awacs_amp {
  33. unsigned char amp_master;
  34. unsigned char amp_vol[2][2];
  35. unsigned char amp_tone[2];
  36. };
  37. #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
  38. #endif /* PMAC_AMP_AVAIL */
  39. static void snd_pmac_screamer_wait(struct snd_pmac *chip)
  40. {
  41. long timeout = 2000;
  42. while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
  43. mdelay(1);
  44. if (! --timeout) {
  45. snd_printd("snd_pmac_screamer_wait timeout\n");
  46. break;
  47. }
  48. }
  49. }
  50. /*
  51. * write AWACS register
  52. */
  53. static void
  54. snd_pmac_awacs_write(struct snd_pmac *chip, int val)
  55. {
  56. long timeout = 5000000;
  57. if (chip->model == PMAC_SCREAMER)
  58. snd_pmac_screamer_wait(chip);
  59. out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
  60. while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
  61. if (! --timeout) {
  62. snd_printd("snd_pmac_awacs_write timeout\n");
  63. break;
  64. }
  65. }
  66. }
  67. static void
  68. snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
  69. {
  70. snd_pmac_awacs_write(chip, val | (reg << 12));
  71. chip->awacs_reg[reg] = val;
  72. }
  73. static void
  74. snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
  75. {
  76. snd_pmac_awacs_write(chip, val | (reg << 12));
  77. }
  78. #ifdef CONFIG_PM
  79. /* Recalibrate chip */
  80. static void screamer_recalibrate(struct snd_pmac *chip)
  81. {
  82. if (chip->model != PMAC_SCREAMER)
  83. return;
  84. /* Sorry for the horrible delays... I hope to get that improved
  85. * by making the whole PM process asynchronous in a future version
  86. */
  87. snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
  88. if (chip->manufacturer == 0x1)
  89. /* delay for broken crystal part */
  90. msleep(750);
  91. snd_pmac_awacs_write_noreg(chip, 1,
  92. chip->awacs_reg[1] | MASK_RECALIBRATE |
  93. MASK_CMUTE | MASK_AMUTE);
  94. snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
  95. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  96. }
  97. #else
  98. #define screamer_recalibrate(chip) /* NOP */
  99. #endif
  100. /*
  101. * additional callback to set the pcm format
  102. */
  103. static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
  104. {
  105. chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
  106. chip->awacs_reg[1] |= chip->rate_index << 3;
  107. snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
  108. }
  109. /*
  110. * AWACS volume callbacks
  111. */
  112. /*
  113. * volumes: 0-15 stereo
  114. */
  115. static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
  116. struct snd_ctl_elem_info *uinfo)
  117. {
  118. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  119. uinfo->count = 2;
  120. uinfo->value.integer.min = 0;
  121. uinfo->value.integer.max = 15;
  122. return 0;
  123. }
  124. static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
  125. struct snd_ctl_elem_value *ucontrol)
  126. {
  127. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  128. int reg = kcontrol->private_value & 0xff;
  129. int lshift = (kcontrol->private_value >> 8) & 0xff;
  130. int inverted = (kcontrol->private_value >> 16) & 1;
  131. unsigned long flags;
  132. int vol[2];
  133. spin_lock_irqsave(&chip->reg_lock, flags);
  134. vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
  135. vol[1] = chip->awacs_reg[reg] & 0xf;
  136. spin_unlock_irqrestore(&chip->reg_lock, flags);
  137. if (inverted) {
  138. vol[0] = 0x0f - vol[0];
  139. vol[1] = 0x0f - vol[1];
  140. }
  141. ucontrol->value.integer.value[0] = vol[0];
  142. ucontrol->value.integer.value[1] = vol[1];
  143. return 0;
  144. }
  145. static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
  146. struct snd_ctl_elem_value *ucontrol)
  147. {
  148. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  149. int reg = kcontrol->private_value & 0xff;
  150. int lshift = (kcontrol->private_value >> 8) & 0xff;
  151. int inverted = (kcontrol->private_value >> 16) & 1;
  152. int val, oldval;
  153. unsigned long flags;
  154. unsigned int vol[2];
  155. vol[0] = ucontrol->value.integer.value[0];
  156. vol[1] = ucontrol->value.integer.value[1];
  157. if (vol[0] > 0x0f || vol[1] > 0x0f)
  158. return -EINVAL;
  159. if (inverted) {
  160. vol[0] = 0x0f - vol[0];
  161. vol[1] = 0x0f - vol[1];
  162. }
  163. vol[0] &= 0x0f;
  164. vol[1] &= 0x0f;
  165. spin_lock_irqsave(&chip->reg_lock, flags);
  166. oldval = chip->awacs_reg[reg];
  167. val = oldval & ~(0xf | (0xf << lshift));
  168. val |= vol[0] << lshift;
  169. val |= vol[1];
  170. if (oldval != val)
  171. snd_pmac_awacs_write_reg(chip, reg, val);
  172. spin_unlock_irqrestore(&chip->reg_lock, flags);
  173. return oldval != reg;
  174. }
  175. #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
  176. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  177. .info = snd_pmac_awacs_info_volume, \
  178. .get = snd_pmac_awacs_get_volume, \
  179. .put = snd_pmac_awacs_put_volume, \
  180. .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
  181. /*
  182. * mute master/ogain for AWACS: mono
  183. */
  184. static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
  185. struct snd_ctl_elem_value *ucontrol)
  186. {
  187. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  188. int reg = kcontrol->private_value & 0xff;
  189. int shift = (kcontrol->private_value >> 8) & 0xff;
  190. int invert = (kcontrol->private_value >> 16) & 1;
  191. int val;
  192. unsigned long flags;
  193. spin_lock_irqsave(&chip->reg_lock, flags);
  194. val = (chip->awacs_reg[reg] >> shift) & 1;
  195. spin_unlock_irqrestore(&chip->reg_lock, flags);
  196. if (invert)
  197. val = 1 - val;
  198. ucontrol->value.integer.value[0] = val;
  199. return 0;
  200. }
  201. static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
  202. struct snd_ctl_elem_value *ucontrol)
  203. {
  204. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  205. int reg = kcontrol->private_value & 0xff;
  206. int shift = (kcontrol->private_value >> 8) & 0xff;
  207. int invert = (kcontrol->private_value >> 16) & 1;
  208. int mask = 1 << shift;
  209. int val, changed;
  210. unsigned long flags;
  211. spin_lock_irqsave(&chip->reg_lock, flags);
  212. val = chip->awacs_reg[reg] & ~mask;
  213. if (ucontrol->value.integer.value[0] != invert)
  214. val |= mask;
  215. changed = chip->awacs_reg[reg] != val;
  216. if (changed)
  217. snd_pmac_awacs_write_reg(chip, reg, val);
  218. spin_unlock_irqrestore(&chip->reg_lock, flags);
  219. return changed;
  220. }
  221. #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
  222. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  223. .info = snd_pmac_boolean_mono_info, \
  224. .get = snd_pmac_awacs_get_switch, \
  225. .put = snd_pmac_awacs_put_switch, \
  226. .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
  227. #ifdef PMAC_AMP_AVAIL
  228. /*
  229. * controls for perch/whisper extension cards, e.g. G3 desktop
  230. *
  231. * TDA7433 connected via i2c address 0x45 (= 0x8a),
  232. * accessed through cuda
  233. */
  234. static void awacs_set_cuda(int reg, int val)
  235. {
  236. struct adb_request req;
  237. cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
  238. reg, val);
  239. while (! req.complete)
  240. cuda_poll();
  241. }
  242. /*
  243. * level = 0 - 14, 7 = 0 dB
  244. */
  245. static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
  246. {
  247. amp->amp_tone[0] = bass;
  248. amp->amp_tone[1] = treble;
  249. if (bass > 7)
  250. bass = (14 - bass) + 8;
  251. if (treble > 7)
  252. treble = (14 - treble) + 8;
  253. awacs_set_cuda(2, (bass << 4) | treble);
  254. }
  255. /*
  256. * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
  257. */
  258. static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
  259. int lvol, int rvol, int do_check)
  260. {
  261. if (do_check && amp->amp_vol[index][0] == lvol &&
  262. amp->amp_vol[index][1] == rvol)
  263. return 0;
  264. awacs_set_cuda(3 + index, lvol);
  265. awacs_set_cuda(5 + index, rvol);
  266. amp->amp_vol[index][0] = lvol;
  267. amp->amp_vol[index][1] = rvol;
  268. return 1;
  269. }
  270. /*
  271. * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
  272. */
  273. static void awacs_amp_set_master(struct awacs_amp *amp, int vol)
  274. {
  275. amp->amp_master = vol;
  276. if (vol <= 79)
  277. vol = 32 + (79 - vol);
  278. else
  279. vol = 32 - (vol - 79);
  280. awacs_set_cuda(1, vol);
  281. }
  282. static void awacs_amp_free(struct snd_pmac *chip)
  283. {
  284. struct awacs_amp *amp = chip->mixer_data;
  285. if (!amp)
  286. return;
  287. kfree(amp);
  288. chip->mixer_data = NULL;
  289. chip->mixer_free = NULL;
  290. }
  291. /*
  292. * mixer controls
  293. */
  294. static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_info *uinfo)
  296. {
  297. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  298. uinfo->count = 2;
  299. uinfo->value.integer.min = 0;
  300. uinfo->value.integer.max = 31;
  301. return 0;
  302. }
  303. static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
  304. struct snd_ctl_elem_value *ucontrol)
  305. {
  306. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  307. int index = kcontrol->private_value;
  308. struct awacs_amp *amp = chip->mixer_data;
  309. ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
  310. ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
  311. return 0;
  312. }
  313. static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_value *ucontrol)
  315. {
  316. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  317. int index = kcontrol->private_value;
  318. int vol[2];
  319. struct awacs_amp *amp = chip->mixer_data;
  320. vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
  321. | (amp->amp_vol[index][0] & 32);
  322. vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
  323. | (amp->amp_vol[index][1] & 32);
  324. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  325. }
  326. static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
  327. struct snd_ctl_elem_value *ucontrol)
  328. {
  329. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  330. int index = kcontrol->private_value;
  331. struct awacs_amp *amp = chip->mixer_data;
  332. ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
  333. ? 0 : 1;
  334. ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
  335. ? 0 : 1;
  336. return 0;
  337. }
  338. static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
  339. struct snd_ctl_elem_value *ucontrol)
  340. {
  341. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  342. int index = kcontrol->private_value;
  343. int vol[2];
  344. struct awacs_amp *amp = chip->mixer_data;
  345. vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
  346. | (amp->amp_vol[index][0] & 31);
  347. vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
  348. | (amp->amp_vol[index][1] & 31);
  349. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  350. }
  351. static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
  352. struct snd_ctl_elem_info *uinfo)
  353. {
  354. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  355. uinfo->count = 1;
  356. uinfo->value.integer.min = 0;
  357. uinfo->value.integer.max = 14;
  358. return 0;
  359. }
  360. static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
  361. struct snd_ctl_elem_value *ucontrol)
  362. {
  363. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  364. int index = kcontrol->private_value;
  365. struct awacs_amp *amp = chip->mixer_data;
  366. ucontrol->value.integer.value[0] = amp->amp_tone[index];
  367. return 0;
  368. }
  369. static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
  370. struct snd_ctl_elem_value *ucontrol)
  371. {
  372. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  373. int index = kcontrol->private_value;
  374. struct awacs_amp *amp = chip->mixer_data;
  375. unsigned int val;
  376. val = ucontrol->value.integer.value[0];
  377. if (val > 14)
  378. return -EINVAL;
  379. if (val != amp->amp_tone[index]) {
  380. amp->amp_tone[index] = val;
  381. awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
  382. return 1;
  383. }
  384. return 0;
  385. }
  386. static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
  387. struct snd_ctl_elem_info *uinfo)
  388. {
  389. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  390. uinfo->count = 1;
  391. uinfo->value.integer.min = 0;
  392. uinfo->value.integer.max = 99;
  393. return 0;
  394. }
  395. static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
  396. struct snd_ctl_elem_value *ucontrol)
  397. {
  398. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  399. struct awacs_amp *amp = chip->mixer_data;
  400. ucontrol->value.integer.value[0] = amp->amp_master;
  401. return 0;
  402. }
  403. static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
  404. struct snd_ctl_elem_value *ucontrol)
  405. {
  406. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  407. struct awacs_amp *amp = chip->mixer_data;
  408. unsigned int val;
  409. val = ucontrol->value.integer.value[0];
  410. if (val > 99)
  411. return -EINVAL;
  412. if (val != amp->amp_master) {
  413. amp->amp_master = val;
  414. awacs_amp_set_master(amp, amp->amp_master);
  415. return 1;
  416. }
  417. return 0;
  418. }
  419. #define AMP_CH_SPK 0
  420. #define AMP_CH_HD 1
  421. static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = {
  422. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  423. .name = "PC Speaker Playback Volume",
  424. .info = snd_pmac_awacs_info_volume_amp,
  425. .get = snd_pmac_awacs_get_volume_amp,
  426. .put = snd_pmac_awacs_put_volume_amp,
  427. .private_value = AMP_CH_SPK,
  428. },
  429. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  430. .name = "Headphone Playback Volume",
  431. .info = snd_pmac_awacs_info_volume_amp,
  432. .get = snd_pmac_awacs_get_volume_amp,
  433. .put = snd_pmac_awacs_put_volume_amp,
  434. .private_value = AMP_CH_HD,
  435. },
  436. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  437. .name = "Tone Control - Bass",
  438. .info = snd_pmac_awacs_info_tone_amp,
  439. .get = snd_pmac_awacs_get_tone_amp,
  440. .put = snd_pmac_awacs_put_tone_amp,
  441. .private_value = 0,
  442. },
  443. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  444. .name = "Tone Control - Treble",
  445. .info = snd_pmac_awacs_info_tone_amp,
  446. .get = snd_pmac_awacs_get_tone_amp,
  447. .put = snd_pmac_awacs_put_tone_amp,
  448. .private_value = 1,
  449. },
  450. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  451. .name = "Amp Master Playback Volume",
  452. .info = snd_pmac_awacs_info_master_amp,
  453. .get = snd_pmac_awacs_get_master_amp,
  454. .put = snd_pmac_awacs_put_master_amp,
  455. },
  456. };
  457. static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = {
  458. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  459. .name = "Headphone Playback Switch",
  460. .info = snd_pmac_boolean_stereo_info,
  461. .get = snd_pmac_awacs_get_switch_amp,
  462. .put = snd_pmac_awacs_put_switch_amp,
  463. .private_value = AMP_CH_HD,
  464. };
  465. static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = {
  466. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  467. .name = "PC Speaker Playback Switch",
  468. .info = snd_pmac_boolean_stereo_info,
  469. .get = snd_pmac_awacs_get_switch_amp,
  470. .put = snd_pmac_awacs_put_switch_amp,
  471. .private_value = AMP_CH_SPK,
  472. };
  473. #endif /* PMAC_AMP_AVAIL */
  474. /*
  475. * mic boost for screamer
  476. */
  477. static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
  478. struct snd_ctl_elem_info *uinfo)
  479. {
  480. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  481. uinfo->count = 1;
  482. uinfo->value.integer.min = 0;
  483. uinfo->value.integer.max = 3;
  484. return 0;
  485. }
  486. static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
  487. struct snd_ctl_elem_value *ucontrol)
  488. {
  489. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  490. int val = 0;
  491. unsigned long flags;
  492. spin_lock_irqsave(&chip->reg_lock, flags);
  493. if (chip->awacs_reg[6] & MASK_MIC_BOOST)
  494. val |= 2;
  495. if (chip->awacs_reg[0] & MASK_GAINLINE)
  496. val |= 1;
  497. spin_unlock_irqrestore(&chip->reg_lock, flags);
  498. ucontrol->value.integer.value[0] = val;
  499. return 0;
  500. }
  501. static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_value *ucontrol)
  503. {
  504. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  505. int changed = 0;
  506. int val0, val6;
  507. unsigned long flags;
  508. spin_lock_irqsave(&chip->reg_lock, flags);
  509. val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
  510. val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
  511. if (ucontrol->value.integer.value[0] & 1)
  512. val0 |= MASK_GAINLINE;
  513. if (ucontrol->value.integer.value[0] & 2)
  514. val6 |= MASK_MIC_BOOST;
  515. if (val0 != chip->awacs_reg[0]) {
  516. snd_pmac_awacs_write_reg(chip, 0, val0);
  517. changed = 1;
  518. }
  519. if (val6 != chip->awacs_reg[6]) {
  520. snd_pmac_awacs_write_reg(chip, 6, val6);
  521. changed = 1;
  522. }
  523. spin_unlock_irqrestore(&chip->reg_lock, flags);
  524. return changed;
  525. }
  526. /*
  527. * lists of mixer elements
  528. */
  529. static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
  530. AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
  531. AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
  532. /* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
  533. };
  534. static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
  535. AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
  536. AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
  537. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  538. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
  539. };
  540. static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
  541. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  542. AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
  543. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  544. };
  545. static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __initdata = {
  546. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  547. AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
  548. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  549. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  550. };
  551. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
  552. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  553. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  554. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  555. };
  556. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
  557. AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
  558. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  559. };
  560. /* FIXME: is this correct order?
  561. * screamer (powerbook G3 pismo) seems to have different bits...
  562. */
  563. static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = {
  564. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
  565. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
  566. };
  567. static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
  568. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  569. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
  570. };
  571. static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
  572. AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
  573. static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
  574. AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
  575. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
  576. AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  577. };
  578. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
  579. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  580. .name = "Mic Boost Capture Volume",
  581. .info = snd_pmac_screamer_mic_boost_info,
  582. .get = snd_pmac_screamer_mic_boost_get,
  583. .put = snd_pmac_screamer_mic_boost_put,
  584. },
  585. };
  586. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
  587. {
  588. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  589. };
  590. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
  591. {
  592. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  593. AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  594. };
  595. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
  596. {
  597. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  598. AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  599. };
  600. static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
  601. AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
  602. };
  603. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
  604. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
  605. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __initdata =
  606. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
  607. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __initdata =
  608. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
  609. /*
  610. * add new mixer elements to the card
  611. */
  612. static int build_mixers(struct snd_pmac *chip, int nums,
  613. struct snd_kcontrol_new *mixers)
  614. {
  615. int i, err;
  616. for (i = 0; i < nums; i++) {
  617. err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
  618. if (err < 0)
  619. return err;
  620. }
  621. return 0;
  622. }
  623. /*
  624. * restore all registers
  625. */
  626. static void awacs_restore_all_regs(struct snd_pmac *chip)
  627. {
  628. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  629. snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
  630. snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
  631. snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
  632. if (chip->model == PMAC_SCREAMER) {
  633. snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
  634. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  635. snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
  636. }
  637. }
  638. #ifdef CONFIG_PM
  639. static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
  640. {
  641. snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
  642. | MASK_AMUTE | MASK_CMUTE));
  643. }
  644. static void snd_pmac_awacs_resume(struct snd_pmac *chip)
  645. {
  646. if (machine_is_compatible("PowerBook3,1")
  647. || machine_is_compatible("PowerBook3,2")) {
  648. msleep(100);
  649. snd_pmac_awacs_write_reg(chip, 1,
  650. chip->awacs_reg[1] & ~MASK_PAROUT);
  651. msleep(300);
  652. }
  653. awacs_restore_all_regs(chip);
  654. if (chip->model == PMAC_SCREAMER) {
  655. /* reset power bits in reg 6 */
  656. mdelay(5);
  657. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  658. }
  659. screamer_recalibrate(chip);
  660. #ifdef PMAC_AMP_AVAIL
  661. if (chip->mixer_data) {
  662. struct awacs_amp *amp = chip->mixer_data;
  663. awacs_amp_set_vol(amp, 0,
  664. amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
  665. awacs_amp_set_vol(amp, 1,
  666. amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
  667. awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
  668. awacs_amp_set_master(amp, amp->amp_master);
  669. }
  670. #endif
  671. }
  672. #endif /* CONFIG_PM */
  673. #define IS_PM7500 (machine_is_compatible("AAPL,7500"))
  674. #define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
  675. #define IS_IMAC1 (machine_is_compatible("PowerMac2,1"))
  676. #define IS_IMAC2 (machine_is_compatible("PowerMac2,2") \
  677. || machine_is_compatible("PowerMac4,1"))
  678. #define IS_G4AGP (machine_is_compatible("PowerMac3,1"))
  679. static int imac1, imac2;
  680. #ifdef PMAC_SUPPORT_AUTOMUTE
  681. /*
  682. * auto-mute stuffs
  683. */
  684. static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
  685. {
  686. return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
  687. }
  688. #ifdef PMAC_AMP_AVAIL
  689. static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
  690. {
  691. int vol[2];
  692. vol[0] = amp->amp_vol[index][0] & 31;
  693. vol[1] = amp->amp_vol[index][1] & 31;
  694. if (mute) {
  695. vol[0] |= 32;
  696. vol[1] |= 32;
  697. }
  698. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  699. }
  700. #endif
  701. static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
  702. {
  703. if (chip->auto_mute) {
  704. #ifdef PMAC_AMP_AVAIL
  705. if (chip->mixer_data) {
  706. struct awacs_amp *amp = chip->mixer_data;
  707. int changed;
  708. if (snd_pmac_awacs_detect_headphone(chip)) {
  709. changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
  710. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
  711. } else {
  712. changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
  713. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
  714. }
  715. if (do_notify && ! changed)
  716. return;
  717. } else
  718. #endif
  719. {
  720. int reg = chip->awacs_reg[1]
  721. | (MASK_HDMUTE | MASK_SPKMUTE);
  722. if (imac1) {
  723. reg &= ~MASK_SPKMUTE;
  724. reg |= MASK_PAROUT1;
  725. } else if (imac2) {
  726. reg &= ~MASK_SPKMUTE;
  727. reg &= ~MASK_PAROUT1;
  728. }
  729. if (snd_pmac_awacs_detect_headphone(chip))
  730. reg &= ~MASK_HDMUTE;
  731. else if (imac1)
  732. reg &= ~MASK_PAROUT1;
  733. else if (imac2)
  734. reg |= MASK_PAROUT1;
  735. else
  736. reg &= ~MASK_SPKMUTE;
  737. if (do_notify && reg == chip->awacs_reg[1])
  738. return;
  739. snd_pmac_awacs_write_reg(chip, 1, reg);
  740. }
  741. if (do_notify) {
  742. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  743. &chip->master_sw_ctl->id);
  744. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  745. &chip->speaker_sw_ctl->id);
  746. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  747. &chip->hp_detect_ctl->id);
  748. }
  749. }
  750. }
  751. #endif /* PMAC_SUPPORT_AUTOMUTE */
  752. /*
  753. * initialize chip
  754. */
  755. int __init
  756. snd_pmac_awacs_init(struct snd_pmac *chip)
  757. {
  758. int pm7500 = IS_PM7500;
  759. int beige = IS_BEIGE;
  760. int g4agp = IS_G4AGP;
  761. int imac;
  762. int err, vol;
  763. imac1 = IS_IMAC1;
  764. imac2 = IS_IMAC2;
  765. imac = imac1 || imac2;
  766. /* looks like MASK_GAINLINE triggers something, so we set here
  767. * as start-up
  768. */
  769. chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
  770. chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
  771. /* FIXME: Only machines with external SRS module need MASK_PAROUT */
  772. if (chip->has_iic || chip->device_id == 0x5 ||
  773. /* chip->_device_id == 0x8 || */
  774. chip->device_id == 0xb)
  775. chip->awacs_reg[1] |= MASK_PAROUT;
  776. /* get default volume from nvram */
  777. // vol = (~nvram_read_byte(0x1308) & 7) << 1;
  778. // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
  779. vol = 0x0f; /* no, on alsa, muted as default */
  780. vol = vol + (vol << 6);
  781. chip->awacs_reg[2] = vol;
  782. chip->awacs_reg[4] = vol;
  783. if (chip->model == PMAC_SCREAMER) {
  784. /* FIXME: screamer has loopthru vol control */
  785. chip->awacs_reg[5] = vol;
  786. /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
  787. chip->awacs_reg[6] = MASK_MIC_BOOST;
  788. chip->awacs_reg[7] = 0;
  789. }
  790. awacs_restore_all_regs(chip);
  791. chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
  792. screamer_recalibrate(chip);
  793. chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
  794. #ifdef PMAC_AMP_AVAIL
  795. if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
  796. struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
  797. if (! amp)
  798. return -ENOMEM;
  799. chip->mixer_data = amp;
  800. chip->mixer_free = awacs_amp_free;
  801. /* mute and zero vol */
  802. awacs_amp_set_vol(amp, 0, 63, 63, 0);
  803. awacs_amp_set_vol(amp, 1, 63, 63, 0);
  804. awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
  805. awacs_amp_set_master(amp, 79); /* 0 dB */
  806. }
  807. #endif /* PMAC_AMP_AVAIL */
  808. if (chip->hp_stat_mask == 0) {
  809. /* set headphone-jack detection bit */
  810. switch (chip->model) {
  811. case PMAC_AWACS:
  812. chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
  813. : MASK_LOCONN;
  814. break;
  815. case PMAC_SCREAMER:
  816. switch (chip->device_id) {
  817. case 0x08:
  818. case 0x0B:
  819. chip->hp_stat_mask = imac
  820. ? MASK_LOCONN_IMAC |
  821. MASK_HDPLCONN_IMAC |
  822. MASK_HDPRCONN_IMAC
  823. : MASK_HDPCONN;
  824. break;
  825. case 0x00:
  826. case 0x05:
  827. chip->hp_stat_mask = MASK_LOCONN;
  828. break;
  829. default:
  830. chip->hp_stat_mask = MASK_HDPCONN;
  831. break;
  832. }
  833. break;
  834. default:
  835. snd_BUG();
  836. break;
  837. }
  838. }
  839. /*
  840. * build mixers
  841. */
  842. strcpy(chip->card->mixername, "PowerMac AWACS");
  843. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
  844. snd_pmac_awacs_mixers);
  845. if (err < 0)
  846. return err;
  847. if (beige || g4agp)
  848. ;
  849. else if (chip->model == PMAC_SCREAMER)
  850. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
  851. snd_pmac_screamer_mixers2);
  852. else if (!pm7500)
  853. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
  854. snd_pmac_awacs_mixers2);
  855. if (err < 0)
  856. return err;
  857. if (pm7500)
  858. err = build_mixers(chip,
  859. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
  860. snd_pmac_awacs_mixers_pmac7500);
  861. else if (beige)
  862. err = build_mixers(chip,
  863. ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
  864. snd_pmac_screamer_mixers_beige);
  865. else if (imac)
  866. err = build_mixers(chip,
  867. ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
  868. snd_pmac_screamer_mixers_imac);
  869. else if (g4agp)
  870. err = build_mixers(chip,
  871. ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
  872. snd_pmac_screamer_mixers_g4agp);
  873. else
  874. err = build_mixers(chip,
  875. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
  876. snd_pmac_awacs_mixers_pmac);
  877. if (err < 0)
  878. return err;
  879. chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp)
  880. ? &snd_pmac_awacs_master_sw_imac
  881. : &snd_pmac_awacs_master_sw, chip);
  882. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  883. if (err < 0)
  884. return err;
  885. #ifdef PMAC_AMP_AVAIL
  886. if (chip->mixer_data) {
  887. /* use amplifier. the signal is connected from route A
  888. * to the amp. the amp has its headphone and speaker
  889. * volumes and mute switches, so we use them instead of
  890. * screamer registers.
  891. * in this case, it seems the route C is not used.
  892. */
  893. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
  894. snd_pmac_awacs_amp_vol);
  895. if (err < 0)
  896. return err;
  897. /* overwrite */
  898. chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
  899. chip);
  900. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  901. if (err < 0)
  902. return err;
  903. chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
  904. chip);
  905. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  906. if (err < 0)
  907. return err;
  908. } else
  909. #endif /* PMAC_AMP_AVAIL */
  910. {
  911. /* route A = headphone, route C = speaker */
  912. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
  913. snd_pmac_awacs_speaker_vol);
  914. if (err < 0)
  915. return err;
  916. chip->speaker_sw_ctl = snd_ctl_new1(imac1
  917. ? &snd_pmac_awacs_speaker_sw_imac1
  918. : imac2
  919. ? &snd_pmac_awacs_speaker_sw_imac2
  920. : &snd_pmac_awacs_speaker_sw, chip);
  921. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  922. if (err < 0)
  923. return err;
  924. }
  925. if (beige || g4agp)
  926. err = build_mixers(chip,
  927. ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
  928. snd_pmac_screamer_mic_boost_beige);
  929. else if (imac)
  930. err = build_mixers(chip,
  931. ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
  932. snd_pmac_screamer_mic_boost_imac);
  933. else if (chip->model == PMAC_SCREAMER)
  934. err = build_mixers(chip,
  935. ARRAY_SIZE(snd_pmac_screamer_mic_boost),
  936. snd_pmac_screamer_mic_boost);
  937. else if (pm7500)
  938. err = build_mixers(chip,
  939. ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
  940. snd_pmac_awacs_mic_boost_pmac7500);
  941. else
  942. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
  943. snd_pmac_awacs_mic_boost);
  944. if (err < 0)
  945. return err;
  946. /*
  947. * set lowlevel callbacks
  948. */
  949. chip->set_format = snd_pmac_awacs_set_format;
  950. #ifdef CONFIG_PM
  951. chip->suspend = snd_pmac_awacs_suspend;
  952. chip->resume = snd_pmac_awacs_resume;
  953. #endif
  954. #ifdef PMAC_SUPPORT_AUTOMUTE
  955. err = snd_pmac_add_automute(chip);
  956. if (err < 0)
  957. return err;
  958. chip->detect_headphone = snd_pmac_awacs_detect_headphone;
  959. chip->update_automute = snd_pmac_awacs_update_automute;
  960. snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
  961. #endif
  962. if (chip->model == PMAC_SCREAMER) {
  963. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  964. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  965. }
  966. return 0;
  967. }