awacs.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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. snd_assert(amp, return);
  286. kfree(amp);
  287. chip->mixer_data = NULL;
  288. chip->mixer_free = NULL;
  289. }
  290. /*
  291. * mixer controls
  292. */
  293. static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
  294. struct snd_ctl_elem_info *uinfo)
  295. {
  296. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  297. uinfo->count = 2;
  298. uinfo->value.integer.min = 0;
  299. uinfo->value.integer.max = 31;
  300. return 0;
  301. }
  302. static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
  303. struct snd_ctl_elem_value *ucontrol)
  304. {
  305. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  306. int index = kcontrol->private_value;
  307. struct awacs_amp *amp = chip->mixer_data;
  308. snd_assert(amp, return -EINVAL);
  309. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  310. ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
  311. ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
  312. return 0;
  313. }
  314. static int snd_pmac_awacs_put_volume_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. int vol[2];
  320. struct awacs_amp *amp = chip->mixer_data;
  321. snd_assert(amp, return -EINVAL);
  322. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  323. vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
  324. | (amp->amp_vol[index][0] & 32);
  325. vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
  326. | (amp->amp_vol[index][1] & 32);
  327. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  328. }
  329. static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
  330. struct snd_ctl_elem_value *ucontrol)
  331. {
  332. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  333. int index = kcontrol->private_value;
  334. struct awacs_amp *amp = chip->mixer_data;
  335. snd_assert(amp, return -EINVAL);
  336. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  337. ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
  338. ? 0 : 1;
  339. ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
  340. ? 0 : 1;
  341. return 0;
  342. }
  343. static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
  344. struct snd_ctl_elem_value *ucontrol)
  345. {
  346. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  347. int index = kcontrol->private_value;
  348. int vol[2];
  349. struct awacs_amp *amp = chip->mixer_data;
  350. snd_assert(amp, return -EINVAL);
  351. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  352. vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
  353. | (amp->amp_vol[index][0] & 31);
  354. vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
  355. | (amp->amp_vol[index][1] & 31);
  356. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  357. }
  358. static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
  359. struct snd_ctl_elem_info *uinfo)
  360. {
  361. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  362. uinfo->count = 1;
  363. uinfo->value.integer.min = 0;
  364. uinfo->value.integer.max = 14;
  365. return 0;
  366. }
  367. static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
  368. struct snd_ctl_elem_value *ucontrol)
  369. {
  370. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  371. int index = kcontrol->private_value;
  372. struct awacs_amp *amp = chip->mixer_data;
  373. snd_assert(amp, return -EINVAL);
  374. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  375. ucontrol->value.integer.value[0] = amp->amp_tone[index];
  376. return 0;
  377. }
  378. static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_value *ucontrol)
  380. {
  381. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  382. int index = kcontrol->private_value;
  383. struct awacs_amp *amp = chip->mixer_data;
  384. unsigned int val;
  385. snd_assert(amp, return -EINVAL);
  386. snd_assert(index >= 0 && index <= 1, return -EINVAL);
  387. val = ucontrol->value.integer.value[0];
  388. if (val > 14)
  389. return -EINVAL;
  390. if (val != amp->amp_tone[index]) {
  391. amp->amp_tone[index] = val;
  392. awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
  393. return 1;
  394. }
  395. return 0;
  396. }
  397. static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_info *uinfo)
  399. {
  400. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  401. uinfo->count = 1;
  402. uinfo->value.integer.min = 0;
  403. uinfo->value.integer.max = 99;
  404. return 0;
  405. }
  406. static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
  407. struct snd_ctl_elem_value *ucontrol)
  408. {
  409. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  410. struct awacs_amp *amp = chip->mixer_data;
  411. snd_assert(amp, return -EINVAL);
  412. ucontrol->value.integer.value[0] = amp->amp_master;
  413. return 0;
  414. }
  415. static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
  416. struct snd_ctl_elem_value *ucontrol)
  417. {
  418. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  419. struct awacs_amp *amp = chip->mixer_data;
  420. unsigned int val;
  421. snd_assert(amp, return -EINVAL);
  422. val = ucontrol->value.integer.value[0];
  423. if (val > 99)
  424. return -EINVAL;
  425. if (val != amp->amp_master) {
  426. amp->amp_master = val;
  427. awacs_amp_set_master(amp, amp->amp_master);
  428. return 1;
  429. }
  430. return 0;
  431. }
  432. #define AMP_CH_SPK 0
  433. #define AMP_CH_HD 1
  434. static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = {
  435. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  436. .name = "PC Speaker Playback Volume",
  437. .info = snd_pmac_awacs_info_volume_amp,
  438. .get = snd_pmac_awacs_get_volume_amp,
  439. .put = snd_pmac_awacs_put_volume_amp,
  440. .private_value = AMP_CH_SPK,
  441. },
  442. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  443. .name = "Headphone Playback Volume",
  444. .info = snd_pmac_awacs_info_volume_amp,
  445. .get = snd_pmac_awacs_get_volume_amp,
  446. .put = snd_pmac_awacs_put_volume_amp,
  447. .private_value = AMP_CH_HD,
  448. },
  449. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  450. .name = "Tone Control - Bass",
  451. .info = snd_pmac_awacs_info_tone_amp,
  452. .get = snd_pmac_awacs_get_tone_amp,
  453. .put = snd_pmac_awacs_put_tone_amp,
  454. .private_value = 0,
  455. },
  456. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  457. .name = "Tone Control - Treble",
  458. .info = snd_pmac_awacs_info_tone_amp,
  459. .get = snd_pmac_awacs_get_tone_amp,
  460. .put = snd_pmac_awacs_put_tone_amp,
  461. .private_value = 1,
  462. },
  463. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  464. .name = "Amp Master Playback Volume",
  465. .info = snd_pmac_awacs_info_master_amp,
  466. .get = snd_pmac_awacs_get_master_amp,
  467. .put = snd_pmac_awacs_put_master_amp,
  468. },
  469. };
  470. static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = {
  471. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  472. .name = "Headphone Playback Switch",
  473. .info = snd_pmac_boolean_stereo_info,
  474. .get = snd_pmac_awacs_get_switch_amp,
  475. .put = snd_pmac_awacs_put_switch_amp,
  476. .private_value = AMP_CH_HD,
  477. };
  478. static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = {
  479. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  480. .name = "PC Speaker Playback Switch",
  481. .info = snd_pmac_boolean_stereo_info,
  482. .get = snd_pmac_awacs_get_switch_amp,
  483. .put = snd_pmac_awacs_put_switch_amp,
  484. .private_value = AMP_CH_SPK,
  485. };
  486. #endif /* PMAC_AMP_AVAIL */
  487. /*
  488. * mic boost for screamer
  489. */
  490. static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
  491. struct snd_ctl_elem_info *uinfo)
  492. {
  493. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  494. uinfo->count = 1;
  495. uinfo->value.integer.min = 0;
  496. uinfo->value.integer.max = 3;
  497. return 0;
  498. }
  499. static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
  500. struct snd_ctl_elem_value *ucontrol)
  501. {
  502. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  503. int val = 0;
  504. unsigned long flags;
  505. spin_lock_irqsave(&chip->reg_lock, flags);
  506. if (chip->awacs_reg[6] & MASK_MIC_BOOST)
  507. val |= 2;
  508. if (chip->awacs_reg[0] & MASK_GAINLINE)
  509. val |= 1;
  510. spin_unlock_irqrestore(&chip->reg_lock, flags);
  511. ucontrol->value.integer.value[0] = val;
  512. return 0;
  513. }
  514. static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
  515. struct snd_ctl_elem_value *ucontrol)
  516. {
  517. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  518. int changed = 0;
  519. int val0, val6;
  520. unsigned long flags;
  521. spin_lock_irqsave(&chip->reg_lock, flags);
  522. val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
  523. val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
  524. if (ucontrol->value.integer.value[0] & 1)
  525. val0 |= MASK_GAINLINE;
  526. if (ucontrol->value.integer.value[0] & 2)
  527. val6 |= MASK_MIC_BOOST;
  528. if (val0 != chip->awacs_reg[0]) {
  529. snd_pmac_awacs_write_reg(chip, 0, val0);
  530. changed = 1;
  531. }
  532. if (val6 != chip->awacs_reg[6]) {
  533. snd_pmac_awacs_write_reg(chip, 6, val6);
  534. changed = 1;
  535. }
  536. spin_unlock_irqrestore(&chip->reg_lock, flags);
  537. return changed;
  538. }
  539. /*
  540. * lists of mixer elements
  541. */
  542. static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
  543. AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
  544. AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
  545. /* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
  546. };
  547. static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
  548. AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
  549. AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
  550. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  551. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
  552. };
  553. static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
  554. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  555. AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
  556. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  557. };
  558. static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __initdata = {
  559. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  560. AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
  561. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  562. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  563. };
  564. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
  565. AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
  566. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  567. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  568. };
  569. static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
  570. AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
  571. AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
  572. };
  573. /* FIXME: is this correct order?
  574. * screamer (powerbook G3 pismo) seems to have different bits...
  575. */
  576. static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = {
  577. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
  578. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
  579. };
  580. static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
  581. AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
  582. AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
  583. };
  584. static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
  585. AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
  586. static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
  587. AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
  588. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
  589. AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  590. };
  591. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
  592. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  593. .name = "Mic Boost Capture Volume",
  594. .info = snd_pmac_screamer_mic_boost_info,
  595. .get = snd_pmac_screamer_mic_boost_get,
  596. .put = snd_pmac_screamer_mic_boost_put,
  597. },
  598. };
  599. static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
  600. {
  601. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  602. };
  603. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
  604. {
  605. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  606. AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  607. };
  608. static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
  609. {
  610. AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
  611. AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
  612. };
  613. static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
  614. AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
  615. };
  616. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
  617. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
  618. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __initdata =
  619. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
  620. static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __initdata =
  621. AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
  622. /*
  623. * add new mixer elements to the card
  624. */
  625. static int build_mixers(struct snd_pmac *chip, int nums,
  626. struct snd_kcontrol_new *mixers)
  627. {
  628. int i, err;
  629. for (i = 0; i < nums; i++) {
  630. err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
  631. if (err < 0)
  632. return err;
  633. }
  634. return 0;
  635. }
  636. /*
  637. * restore all registers
  638. */
  639. static void awacs_restore_all_regs(struct snd_pmac *chip)
  640. {
  641. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  642. snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
  643. snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
  644. snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
  645. if (chip->model == PMAC_SCREAMER) {
  646. snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
  647. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  648. snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
  649. }
  650. }
  651. #ifdef CONFIG_PM
  652. static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
  653. {
  654. snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
  655. | MASK_AMUTE | MASK_CMUTE));
  656. }
  657. static void snd_pmac_awacs_resume(struct snd_pmac *chip)
  658. {
  659. if (machine_is_compatible("PowerBook3,1")
  660. || machine_is_compatible("PowerBook3,2")) {
  661. msleep(100);
  662. snd_pmac_awacs_write_reg(chip, 1,
  663. chip->awacs_reg[1] & ~MASK_PAROUT);
  664. msleep(300);
  665. }
  666. awacs_restore_all_regs(chip);
  667. if (chip->model == PMAC_SCREAMER) {
  668. /* reset power bits in reg 6 */
  669. mdelay(5);
  670. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  671. }
  672. screamer_recalibrate(chip);
  673. #ifdef PMAC_AMP_AVAIL
  674. if (chip->mixer_data) {
  675. struct awacs_amp *amp = chip->mixer_data;
  676. awacs_amp_set_vol(amp, 0,
  677. amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
  678. awacs_amp_set_vol(amp, 1,
  679. amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
  680. awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
  681. awacs_amp_set_master(amp, amp->amp_master);
  682. }
  683. #endif
  684. }
  685. #endif /* CONFIG_PM */
  686. #define IS_PM7500 (machine_is_compatible("AAPL,7500"))
  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. static int imac1, imac2;
  693. #ifdef PMAC_SUPPORT_AUTOMUTE
  694. /*
  695. * auto-mute stuffs
  696. */
  697. static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
  698. {
  699. return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
  700. }
  701. #ifdef PMAC_AMP_AVAIL
  702. static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
  703. {
  704. int vol[2];
  705. vol[0] = amp->amp_vol[index][0] & 31;
  706. vol[1] = amp->amp_vol[index][1] & 31;
  707. if (mute) {
  708. vol[0] |= 32;
  709. vol[1] |= 32;
  710. }
  711. return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
  712. }
  713. #endif
  714. static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
  715. {
  716. if (chip->auto_mute) {
  717. #ifdef PMAC_AMP_AVAIL
  718. if (chip->mixer_data) {
  719. struct awacs_amp *amp = chip->mixer_data;
  720. int changed;
  721. if (snd_pmac_awacs_detect_headphone(chip)) {
  722. changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
  723. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
  724. } else {
  725. changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
  726. changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
  727. }
  728. if (do_notify && ! changed)
  729. return;
  730. } else
  731. #endif
  732. {
  733. int reg = chip->awacs_reg[1]
  734. | (MASK_HDMUTE | MASK_SPKMUTE);
  735. if (imac1) {
  736. reg &= ~MASK_SPKMUTE;
  737. reg |= MASK_PAROUT1;
  738. } else if (imac2) {
  739. reg &= ~MASK_SPKMUTE;
  740. reg &= ~MASK_PAROUT1;
  741. }
  742. if (snd_pmac_awacs_detect_headphone(chip))
  743. reg &= ~MASK_HDMUTE;
  744. else if (imac1)
  745. reg &= ~MASK_PAROUT1;
  746. else if (imac2)
  747. reg |= MASK_PAROUT1;
  748. else
  749. reg &= ~MASK_SPKMUTE;
  750. if (do_notify && reg == chip->awacs_reg[1])
  751. return;
  752. snd_pmac_awacs_write_reg(chip, 1, reg);
  753. }
  754. if (do_notify) {
  755. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  756. &chip->master_sw_ctl->id);
  757. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  758. &chip->speaker_sw_ctl->id);
  759. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  760. &chip->hp_detect_ctl->id);
  761. }
  762. }
  763. }
  764. #endif /* PMAC_SUPPORT_AUTOMUTE */
  765. /*
  766. * initialize chip
  767. */
  768. int __init
  769. snd_pmac_awacs_init(struct snd_pmac *chip)
  770. {
  771. int pm7500 = IS_PM7500;
  772. int beige = IS_BEIGE;
  773. int g4agp = IS_G4AGP;
  774. int imac;
  775. int err, vol;
  776. imac1 = IS_IMAC1;
  777. imac2 = IS_IMAC2;
  778. imac = imac1 || imac2;
  779. /* looks like MASK_GAINLINE triggers something, so we set here
  780. * as start-up
  781. */
  782. chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
  783. chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
  784. /* FIXME: Only machines with external SRS module need MASK_PAROUT */
  785. if (chip->has_iic || chip->device_id == 0x5 ||
  786. /* chip->_device_id == 0x8 || */
  787. chip->device_id == 0xb)
  788. chip->awacs_reg[1] |= MASK_PAROUT;
  789. /* get default volume from nvram */
  790. // vol = (~nvram_read_byte(0x1308) & 7) << 1;
  791. // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
  792. vol = 0x0f; /* no, on alsa, muted as default */
  793. vol = vol + (vol << 6);
  794. chip->awacs_reg[2] = vol;
  795. chip->awacs_reg[4] = vol;
  796. if (chip->model == PMAC_SCREAMER) {
  797. /* FIXME: screamer has loopthru vol control */
  798. chip->awacs_reg[5] = vol;
  799. /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
  800. chip->awacs_reg[6] = MASK_MIC_BOOST;
  801. chip->awacs_reg[7] = 0;
  802. }
  803. awacs_restore_all_regs(chip);
  804. chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
  805. screamer_recalibrate(chip);
  806. chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
  807. #ifdef PMAC_AMP_AVAIL
  808. if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
  809. struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
  810. if (! amp)
  811. return -ENOMEM;
  812. chip->mixer_data = amp;
  813. chip->mixer_free = awacs_amp_free;
  814. /* mute and zero vol */
  815. awacs_amp_set_vol(amp, 0, 63, 63, 0);
  816. awacs_amp_set_vol(amp, 1, 63, 63, 0);
  817. awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
  818. awacs_amp_set_master(amp, 79); /* 0 dB */
  819. }
  820. #endif /* PMAC_AMP_AVAIL */
  821. if (chip->hp_stat_mask == 0) {
  822. /* set headphone-jack detection bit */
  823. switch (chip->model) {
  824. case PMAC_AWACS:
  825. chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
  826. : MASK_LOCONN;
  827. break;
  828. case PMAC_SCREAMER:
  829. switch (chip->device_id) {
  830. case 0x08:
  831. case 0x0B:
  832. chip->hp_stat_mask = imac
  833. ? MASK_LOCONN_IMAC |
  834. MASK_HDPLCONN_IMAC |
  835. MASK_HDPRCONN_IMAC
  836. : MASK_HDPCONN;
  837. break;
  838. case 0x00:
  839. case 0x05:
  840. chip->hp_stat_mask = MASK_LOCONN;
  841. break;
  842. default:
  843. chip->hp_stat_mask = MASK_HDPCONN;
  844. break;
  845. }
  846. break;
  847. default:
  848. snd_BUG();
  849. break;
  850. }
  851. }
  852. /*
  853. * build mixers
  854. */
  855. strcpy(chip->card->mixername, "PowerMac AWACS");
  856. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
  857. snd_pmac_awacs_mixers);
  858. if (err < 0)
  859. return err;
  860. if (beige || g4agp)
  861. ;
  862. else if (chip->model == PMAC_SCREAMER)
  863. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
  864. snd_pmac_screamer_mixers2);
  865. else if (!pm7500)
  866. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
  867. snd_pmac_awacs_mixers2);
  868. if (err < 0)
  869. return err;
  870. if (pm7500)
  871. err = build_mixers(chip,
  872. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
  873. snd_pmac_awacs_mixers_pmac7500);
  874. else if (beige)
  875. err = build_mixers(chip,
  876. ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
  877. snd_pmac_screamer_mixers_beige);
  878. else if (imac)
  879. err = build_mixers(chip,
  880. ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
  881. snd_pmac_screamer_mixers_imac);
  882. else if (g4agp)
  883. err = build_mixers(chip,
  884. ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
  885. snd_pmac_screamer_mixers_g4agp);
  886. else
  887. err = build_mixers(chip,
  888. ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
  889. snd_pmac_awacs_mixers_pmac);
  890. if (err < 0)
  891. return err;
  892. chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp)
  893. ? &snd_pmac_awacs_master_sw_imac
  894. : &snd_pmac_awacs_master_sw, chip);
  895. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  896. if (err < 0)
  897. return err;
  898. #ifdef PMAC_AMP_AVAIL
  899. if (chip->mixer_data) {
  900. /* use amplifier. the signal is connected from route A
  901. * to the amp. the amp has its headphone and speaker
  902. * volumes and mute switches, so we use them instead of
  903. * screamer registers.
  904. * in this case, it seems the route C is not used.
  905. */
  906. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
  907. snd_pmac_awacs_amp_vol);
  908. if (err < 0)
  909. return err;
  910. /* overwrite */
  911. chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
  912. chip);
  913. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  914. if (err < 0)
  915. return err;
  916. chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
  917. chip);
  918. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  919. if (err < 0)
  920. return err;
  921. } else
  922. #endif /* PMAC_AMP_AVAIL */
  923. {
  924. /* route A = headphone, route C = speaker */
  925. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
  926. snd_pmac_awacs_speaker_vol);
  927. if (err < 0)
  928. return err;
  929. chip->speaker_sw_ctl = snd_ctl_new1(imac1
  930. ? &snd_pmac_awacs_speaker_sw_imac1
  931. : imac2
  932. ? &snd_pmac_awacs_speaker_sw_imac2
  933. : &snd_pmac_awacs_speaker_sw, chip);
  934. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  935. if (err < 0)
  936. return err;
  937. }
  938. if (beige || g4agp)
  939. err = build_mixers(chip,
  940. ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
  941. snd_pmac_screamer_mic_boost_beige);
  942. else if (imac)
  943. err = build_mixers(chip,
  944. ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
  945. snd_pmac_screamer_mic_boost_imac);
  946. else if (chip->model == PMAC_SCREAMER)
  947. err = build_mixers(chip,
  948. ARRAY_SIZE(snd_pmac_screamer_mic_boost),
  949. snd_pmac_screamer_mic_boost);
  950. else if (pm7500)
  951. err = build_mixers(chip,
  952. ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
  953. snd_pmac_awacs_mic_boost_pmac7500);
  954. else
  955. err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
  956. snd_pmac_awacs_mic_boost);
  957. if (err < 0)
  958. return err;
  959. /*
  960. * set lowlevel callbacks
  961. */
  962. chip->set_format = snd_pmac_awacs_set_format;
  963. #ifdef CONFIG_PM
  964. chip->suspend = snd_pmac_awacs_suspend;
  965. chip->resume = snd_pmac_awacs_resume;
  966. #endif
  967. #ifdef PMAC_SUPPORT_AUTOMUTE
  968. err = snd_pmac_add_automute(chip);
  969. if (err < 0)
  970. return err;
  971. chip->detect_headphone = snd_pmac_awacs_detect_headphone;
  972. chip->update_automute = snd_pmac_awacs_update_automute;
  973. snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
  974. #endif
  975. if (chip->model == PMAC_SCREAMER) {
  976. snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
  977. snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
  978. }
  979. return 0;
  980. }