awacs.c 31 KB

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