awacs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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[] __devinitdata = {
  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 __devinitdata = {
  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 __devinitdata = {
  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[] __devinitdata = {
  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[] __devinitdata = {
  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_lo[] __devinitdata = {
  541. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  542. };
  543. static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __devinitdata = {
  544. AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
  545. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  546. };
  547. static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __devinitdata = {
  548. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  549. AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
  550. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  551. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  552. };
  553. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __devinitdata = {
  554. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  555. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  556. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  557. };
  558. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac5500[] __devinitdata = {
  559. AWACS_VOLUME("Headphone Playback Volume", 2, 6, 1),
  560. };
  561. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __devinitdata = {
  562. AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
  563. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  564. };
  565. /* FIXME: is this correct order?
  566. * screamer (powerbook G3 pismo) seems to have different bits...
  567. */
  568. static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __devinitdata = {
  569. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
  570. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
  571. };
  572. static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __devinitdata = {
  573. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  574. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
  575. };
  576. static struct snd_kcontrol_new snd_pmac_awacs_mixers2_pmac5500[] __devinitdata = {
  577. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  578. };
  579. static struct snd_kcontrol_new snd_pmac_awacs_master_sw __devinitdata =
  580. AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
  581. static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __devinitdata =
  582. AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
  583. static struct snd_kcontrol_new snd_pmac_awacs_master_sw_pmac5500 __devinitdata =
  584. AWACS_SWITCH("Headphone Playback Switch", 1, SHIFT_HDMUTE, 1);
  585. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __devinitdata = {
  586. AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  587. };
  588. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __devinitdata = {
  589. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  590. .name = "Mic Boost Capture Volume",
  591. .info = snd_pmac_screamer_mic_boost_info,
  592. .get = snd_pmac_screamer_mic_boost_get,
  593. .put = snd_pmac_screamer_mic_boost_put,
  594. },
  595. };
  596. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __devinitdata =
  597. {
  598. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  599. };
  600. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __devinitdata =
  601. {
  602. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  603. AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  604. };
  605. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __devinitdata =
  606. {
  607. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  608. AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  609. };
  610. static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = {
  611. AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
  612. };
  613. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __devinitdata =
  614. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
  615. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata =
  616. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
  617. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata =
  618. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
  619. /*
  620. * add new mixer elements to the card
  621. */
  622. static int build_mixers(struct snd_pmac *chip, int nums,
  623. struct snd_kcontrol_new *mixers)
  624. {
  625. int i, err;
  626. for (i = 0; i < nums; i++) {
  627. err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
  628. if (err < 0)
  629. return err;
  630. }
  631. return 0;
  632. }
  633. /*
  634. * restore all registers
  635. */
  636. static void awacs_restore_all_regs(struct snd_pmac *chip)
  637. {
  638. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  639. snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
  640. snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
  641. snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
  642. if (chip->model == PMAC_SCREAMER) {
  643. snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
  644. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  645. snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
  646. }
  647. }
  648. #ifdef CONFIG_PM
  649. static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
  650. {
  651. snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
  652. | MASK_AMUTE | MASK_CMUTE));
  653. }
  654. static void snd_pmac_awacs_resume(struct snd_pmac *chip)
  655. {
  656. if (machine_is_compatible("PowerBook3,1")
  657. || machine_is_compatible("PowerBook3,2")) {
  658. msleep(100);
  659. snd_pmac_awacs_write_reg(chip, 1,
  660. chip->awacs_reg[1] & ~MASK_PAROUT);
  661. msleep(300);
  662. }
  663. awacs_restore_all_regs(chip);
  664. if (chip->model == PMAC_SCREAMER) {
  665. /* reset power bits in reg 6 */
  666. mdelay(5);
  667. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  668. }
  669. screamer_recalibrate(chip);
  670. #ifdef PMAC_AMP_AVAIL
  671. if (chip->mixer_data) {
  672. struct awacs_amp *amp = chip->mixer_data;
  673. awacs_amp_set_vol(amp, 0,
  674. amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
  675. awacs_amp_set_vol(amp, 1,
  676. amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
  677. awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
  678. awacs_amp_set_master(amp, amp->amp_master);
  679. }
  680. #endif
  681. }
  682. #endif /* CONFIG_PM */
  683. #define IS_PM7500 (machine_is_compatible("AAPL,7500") \
  684. || machine_is_compatible("AAPL,8500") \
  685. || machine_is_compatible("AAPL,9500"))
  686. #define IS_PM5500 (machine_is_compatible("AAPL,e411"))
  687. #define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
  688. #define IS_IMAC1 (machine_is_compatible("PowerMac2,1"))
  689. #define IS_IMAC2 (machine_is_compatible("PowerMac2,2") \
  690. || machine_is_compatible("PowerMac4,1"))
  691. #define IS_G4AGP (machine_is_compatible("PowerMac3,1"))
  692. #define IS_LOMBARD (machine_is_compatible("PowerBook1,1"))
  693. static int imac1, imac2;
  694. #ifdef PMAC_SUPPORT_AUTOMUTE
  695. /*
  696. * auto-mute stuffs
  697. */
  698. static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
  699. {
  700. return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
  701. }
  702. #ifdef PMAC_AMP_AVAIL
  703. static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
  704. {
  705. int vol[2];
  706. vol[0] = amp->amp_vol[index][0] & 31;
  707. vol[1] = amp->amp_vol[index][1] & 31;
  708. if (mute) {
  709. vol[0] |= 32;
  710. vol[1] |= 32;
  711. }
  712. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  713. }
  714. #endif
  715. static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
  716. {
  717. if (chip->auto_mute) {
  718. #ifdef PMAC_AMP_AVAIL
  719. if (chip->mixer_data) {
  720. struct awacs_amp *amp = chip->mixer_data;
  721. int changed;
  722. if (snd_pmac_awacs_detect_headphone(chip)) {
  723. changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
  724. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
  725. } else {
  726. changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
  727. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
  728. }
  729. if (do_notify && ! changed)
  730. return;
  731. } else
  732. #endif
  733. {
  734. int reg = chip->awacs_reg[1]
  735. | (MASK_HDMUTE | MASK_SPKMUTE);
  736. if (imac1) {
  737. reg &= ~MASK_SPKMUTE;
  738. reg |= MASK_PAROUT1;
  739. } else if (imac2) {
  740. reg &= ~MASK_SPKMUTE;
  741. reg &= ~MASK_PAROUT1;
  742. }
  743. if (snd_pmac_awacs_detect_headphone(chip))
  744. reg &= ~MASK_HDMUTE;
  745. else if (imac1)
  746. reg &= ~MASK_PAROUT1;
  747. else if (imac2)
  748. reg |= MASK_PAROUT1;
  749. else
  750. reg &= ~MASK_SPKMUTE;
  751. if (do_notify && reg == chip->awacs_reg[1])
  752. return;
  753. snd_pmac_awacs_write_reg(chip, 1, reg);
  754. }
  755. if (do_notify) {
  756. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  757. &chip->master_sw_ctl->id);
  758. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  759. &chip->speaker_sw_ctl->id);
  760. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  761. &chip->hp_detect_ctl->id);
  762. }
  763. }
  764. }
  765. #endif /* PMAC_SUPPORT_AUTOMUTE */
  766. /*
  767. * initialize chip
  768. */
  769. int __devinit
  770. snd_pmac_awacs_init(struct snd_pmac *chip)
  771. {
  772. int pm7500 = IS_PM7500;
  773. int pm5500 = IS_PM5500;
  774. int beige = IS_BEIGE;
  775. int g4agp = IS_G4AGP;
  776. int lombard = IS_LOMBARD;
  777. int imac;
  778. int err, vol;
  779. struct snd_kcontrol *vmaster_sw, *vmaster_vol;
  780. struct snd_kcontrol *master_vol, *speaker_vol;
  781. imac1 = IS_IMAC1;
  782. imac2 = IS_IMAC2;
  783. imac = imac1 || imac2;
  784. /* looks like MASK_GAINLINE triggers something, so we set here
  785. * as start-up
  786. */
  787. chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
  788. chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
  789. /* FIXME: Only machines with external SRS module need MASK_PAROUT */
  790. if (chip->has_iic || chip->device_id == 0x5 ||
  791. /* chip->_device_id == 0x8 || */
  792. chip->device_id == 0xb)
  793. chip->awacs_reg[1] |= MASK_PAROUT;
  794. /* get default volume from nvram */
  795. // vol = (~nvram_read_byte(0x1308) & 7) << 1;
  796. // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
  797. vol = 0x0f; /* no, on alsa, muted as default */
  798. vol = vol + (vol << 6);
  799. chip->awacs_reg[2] = vol;
  800. chip->awacs_reg[4] = vol;
  801. if (chip->model == PMAC_SCREAMER) {
  802. /* FIXME: screamer has loopthru vol control */
  803. chip->awacs_reg[5] = vol;
  804. /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
  805. chip->awacs_reg[6] = MASK_MIC_BOOST;
  806. chip->awacs_reg[7] = 0;
  807. }
  808. awacs_restore_all_regs(chip);
  809. chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
  810. screamer_recalibrate(chip);
  811. chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
  812. #ifdef PMAC_AMP_AVAIL
  813. if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
  814. struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
  815. if (! amp)
  816. return -ENOMEM;
  817. chip->mixer_data = amp;
  818. chip->mixer_free = awacs_amp_free;
  819. /* mute and zero vol */
  820. awacs_amp_set_vol(amp, 0, 63, 63, 0);
  821. awacs_amp_set_vol(amp, 1, 63, 63, 0);
  822. awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
  823. awacs_amp_set_master(amp, 79); /* 0 dB */
  824. }
  825. #endif /* PMAC_AMP_AVAIL */
  826. if (chip->hp_stat_mask == 0) {
  827. /* set headphone-jack detection bit */
  828. switch (chip->model) {
  829. case PMAC_AWACS:
  830. chip->hp_stat_mask = pm7500 || pm5500 ? MASK_HDPCONN
  831. : MASK_LOCONN;
  832. break;
  833. case PMAC_SCREAMER:
  834. switch (chip->device_id) {
  835. case 0x08:
  836. case 0x0B:
  837. chip->hp_stat_mask = imac
  838. ? MASK_LOCONN_IMAC |
  839. MASK_HDPLCONN_IMAC |
  840. MASK_HDPRCONN_IMAC
  841. : MASK_HDPCONN;
  842. break;
  843. case 0x00:
  844. case 0x05:
  845. chip->hp_stat_mask = MASK_LOCONN;
  846. break;
  847. default:
  848. chip->hp_stat_mask = MASK_HDPCONN;
  849. break;
  850. }
  851. break;
  852. default:
  853. snd_BUG();
  854. break;
  855. }
  856. }
  857. /*
  858. * build mixers
  859. */
  860. strcpy(chip->card->mixername, "PowerMac AWACS");
  861. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
  862. snd_pmac_awacs_mixers);
  863. if (err < 0)
  864. return err;
  865. if (beige || g4agp)
  866. ;
  867. else if (chip->model == PMAC_SCREAMER || pm5500)
  868. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
  869. snd_pmac_screamer_mixers2);
  870. else if (!pm7500)
  871. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
  872. snd_pmac_awacs_mixers2);
  873. if (err < 0)
  874. return err;
  875. if (pm5500) {
  876. err = build_mixers(chip,
  877. ARRAY_SIZE(snd_pmac_awacs_mixers2_pmac5500),
  878. snd_pmac_awacs_mixers2_pmac5500);
  879. if (err < 0)
  880. return err;
  881. }
  882. if (pm7500)
  883. err = build_mixers(chip,
  884. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
  885. snd_pmac_awacs_mixers_pmac7500);
  886. else if (pm5500)
  887. err = snd_ctl_add(chip->card,
  888. (master_vol = snd_ctl_new1(snd_pmac_awacs_mixers_pmac5500,
  889. chip)));
  890. else if (beige)
  891. err = build_mixers(chip,
  892. ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
  893. snd_pmac_screamer_mixers_beige);
  894. else if (imac || lombard) {
  895. err = snd_ctl_add(chip->card,
  896. (master_vol = snd_ctl_new1(snd_pmac_screamer_mixers_lo,
  897. chip)));
  898. if (err < 0)
  899. return err;
  900. err = build_mixers(chip,
  901. ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
  902. snd_pmac_screamer_mixers_imac);
  903. } else if (g4agp)
  904. err = build_mixers(chip,
  905. ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
  906. snd_pmac_screamer_mixers_g4agp);
  907. else
  908. err = build_mixers(chip,
  909. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
  910. snd_pmac_awacs_mixers_pmac);
  911. if (err < 0)
  912. return err;
  913. chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp || lombard)
  914. ? &snd_pmac_awacs_master_sw_imac
  915. : pm5500
  916. ? &snd_pmac_awacs_master_sw_pmac5500
  917. : &snd_pmac_awacs_master_sw, chip);
  918. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  919. if (err < 0)
  920. return err;
  921. #ifdef PMAC_AMP_AVAIL
  922. if (chip->mixer_data) {
  923. /* use amplifier. the signal is connected from route A
  924. * to the amp. the amp has its headphone and speaker
  925. * volumes and mute switches, so we use them instead of
  926. * screamer registers.
  927. * in this case, it seems the route C is not used.
  928. */
  929. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
  930. snd_pmac_awacs_amp_vol);
  931. if (err < 0)
  932. return err;
  933. /* overwrite */
  934. chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
  935. chip);
  936. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  937. if (err < 0)
  938. return err;
  939. chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
  940. chip);
  941. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  942. if (err < 0)
  943. return err;
  944. } else
  945. #endif /* PMAC_AMP_AVAIL */
  946. {
  947. /* route A = headphone, route C = speaker */
  948. err = snd_ctl_add(chip->card,
  949. (speaker_vol = snd_ctl_new1(snd_pmac_awacs_speaker_vol,
  950. chip)));
  951. if (err < 0)
  952. return err;
  953. chip->speaker_sw_ctl = snd_ctl_new1(imac1
  954. ? &snd_pmac_awacs_speaker_sw_imac1
  955. : imac2
  956. ? &snd_pmac_awacs_speaker_sw_imac2
  957. : &snd_pmac_awacs_speaker_sw, chip);
  958. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  959. if (err < 0)
  960. return err;
  961. }
  962. if (pm5500 || imac || lombard) {
  963. vmaster_sw = snd_ctl_make_virtual_master(
  964. "Master Playback Switch", (unsigned int *) NULL);
  965. err = snd_ctl_add_slave_uncached(vmaster_sw,
  966. chip->master_sw_ctl);
  967. if (err < 0)
  968. return err;
  969. err = snd_ctl_add_slave_uncached(vmaster_sw,
  970. chip->speaker_sw_ctl);
  971. if (err < 0)
  972. return err;
  973. err = snd_ctl_add(chip->card, vmaster_sw);
  974. if (err < 0)
  975. return err;
  976. vmaster_vol = snd_ctl_make_virtual_master(
  977. "Master Playback Volume", (unsigned int *) NULL);
  978. err = snd_ctl_add_slave(vmaster_vol, master_vol);
  979. if (err < 0)
  980. return err;
  981. err = snd_ctl_add_slave(vmaster_vol, speaker_vol);
  982. if (err < 0)
  983. return err;
  984. err = snd_ctl_add(chip->card, vmaster_vol);
  985. if (err < 0)
  986. return err;
  987. }
  988. if (beige || g4agp)
  989. err = build_mixers(chip,
  990. ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
  991. snd_pmac_screamer_mic_boost_beige);
  992. else if (imac)
  993. err = build_mixers(chip,
  994. ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
  995. snd_pmac_screamer_mic_boost_imac);
  996. else if (chip->model == PMAC_SCREAMER)
  997. err = build_mixers(chip,
  998. ARRAY_SIZE(snd_pmac_screamer_mic_boost),
  999. snd_pmac_screamer_mic_boost);
  1000. else if (pm7500)
  1001. err = build_mixers(chip,
  1002. ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
  1003. snd_pmac_awacs_mic_boost_pmac7500);
  1004. else
  1005. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
  1006. snd_pmac_awacs_mic_boost);
  1007. if (err < 0)
  1008. return err;
  1009. /*
  1010. * set lowlevel callbacks
  1011. */
  1012. chip->set_format = snd_pmac_awacs_set_format;
  1013. #ifdef CONFIG_PM
  1014. chip->suspend = snd_pmac_awacs_suspend;
  1015. chip->resume = snd_pmac_awacs_resume;
  1016. #endif
  1017. #ifdef PMAC_SUPPORT_AUTOMUTE
  1018. err = snd_pmac_add_automute(chip);
  1019. if (err < 0)
  1020. return err;
  1021. chip->detect_headphone = snd_pmac_awacs_detect_headphone;
  1022. chip->update_automute = snd_pmac_awacs_update_automute;
  1023. snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
  1024. #endif
  1025. if (chip->model == PMAC_SCREAMER) {
  1026. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  1027. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  1028. }
  1029. return 0;
  1030. }