burgundy.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * PMac Burgundy 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 <linux/io.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <sound/core.h>
  25. #include "pmac.h"
  26. #include "burgundy.h"
  27. /* Waits for busy flag to clear */
  28. static inline void
  29. snd_pmac_burgundy_busy_wait(struct snd_pmac *chip)
  30. {
  31. int timeout = 50;
  32. while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--)
  33. udelay(1);
  34. if (timeout < 0)
  35. printk(KERN_DEBUG "burgundy_busy_wait: timeout\n");
  36. }
  37. static inline void
  38. snd_pmac_burgundy_extend_wait(struct snd_pmac *chip)
  39. {
  40. int timeout;
  41. timeout = 50;
  42. while (!(in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
  43. udelay(1);
  44. if (timeout < 0)
  45. printk(KERN_DEBUG "burgundy_extend_wait: timeout #1\n");
  46. timeout = 50;
  47. while ((in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
  48. udelay(1);
  49. if (timeout < 0)
  50. printk(KERN_DEBUG "burgundy_extend_wait: timeout #2\n");
  51. }
  52. static void
  53. snd_pmac_burgundy_wcw(struct snd_pmac *chip, unsigned addr, unsigned val)
  54. {
  55. out_le32(&chip->awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff));
  56. snd_pmac_burgundy_busy_wait(chip);
  57. out_le32(&chip->awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff));
  58. snd_pmac_burgundy_busy_wait(chip);
  59. out_le32(&chip->awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff));
  60. snd_pmac_burgundy_busy_wait(chip);
  61. out_le32(&chip->awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff));
  62. snd_pmac_burgundy_busy_wait(chip);
  63. }
  64. static unsigned
  65. snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
  66. {
  67. unsigned val = 0;
  68. unsigned long flags;
  69. spin_lock_irqsave(&chip->reg_lock, flags);
  70. out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
  71. snd_pmac_burgundy_busy_wait(chip);
  72. snd_pmac_burgundy_extend_wait(chip);
  73. val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
  74. out_le32(&chip->awacs->codec_ctrl, addr + 0x100100);
  75. snd_pmac_burgundy_busy_wait(chip);
  76. snd_pmac_burgundy_extend_wait(chip);
  77. val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<8;
  78. out_le32(&chip->awacs->codec_ctrl, addr + 0x100200);
  79. snd_pmac_burgundy_busy_wait(chip);
  80. snd_pmac_burgundy_extend_wait(chip);
  81. val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<16;
  82. out_le32(&chip->awacs->codec_ctrl, addr + 0x100300);
  83. snd_pmac_burgundy_busy_wait(chip);
  84. snd_pmac_burgundy_extend_wait(chip);
  85. val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24;
  86. spin_unlock_irqrestore(&chip->reg_lock, flags);
  87. return val;
  88. }
  89. static void
  90. snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr,
  91. unsigned int val)
  92. {
  93. out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
  94. snd_pmac_burgundy_busy_wait(chip);
  95. }
  96. static unsigned
  97. snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
  98. {
  99. unsigned val = 0;
  100. unsigned long flags;
  101. spin_lock_irqsave(&chip->reg_lock, flags);
  102. out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
  103. snd_pmac_burgundy_busy_wait(chip);
  104. snd_pmac_burgundy_extend_wait(chip);
  105. val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
  106. spin_unlock_irqrestore(&chip->reg_lock, flags);
  107. return val;
  108. }
  109. #define BASE2ADDR(base) ((base) << 12)
  110. #define ADDR2BASE(addr) ((addr) >> 12)
  111. /*
  112. * Burgundy volume: 0 - 100, stereo, word reg
  113. */
  114. static void
  115. snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
  116. long *volume, int shift)
  117. {
  118. int hardvolume, lvolume, rvolume;
  119. if (volume[0] < 0 || volume[0] > 100 ||
  120. volume[1] < 0 || volume[1] > 100)
  121. return; /* -EINVAL */
  122. lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
  123. rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
  124. hardvolume = lvolume + (rvolume << shift);
  125. if (shift == 8)
  126. hardvolume |= hardvolume << 16;
  127. snd_pmac_burgundy_wcw(chip, address, hardvolume);
  128. }
  129. static void
  130. snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
  131. long *volume, int shift)
  132. {
  133. int wvolume;
  134. wvolume = snd_pmac_burgundy_rcw(chip, address);
  135. volume[0] = wvolume & 0xff;
  136. if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
  137. volume[0] -= BURGUNDY_VOLUME_OFFSET;
  138. else
  139. volume[0] = 0;
  140. volume[1] = (wvolume >> shift) & 0xff;
  141. if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
  142. volume[1] -= BURGUNDY_VOLUME_OFFSET;
  143. else
  144. volume[1] = 0;
  145. }
  146. static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
  147. struct snd_ctl_elem_info *uinfo)
  148. {
  149. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  150. uinfo->count = 2;
  151. uinfo->value.integer.min = 0;
  152. uinfo->value.integer.max = 100;
  153. return 0;
  154. }
  155. static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
  156. struct snd_ctl_elem_value *ucontrol)
  157. {
  158. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  159. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  160. int shift = (kcontrol->private_value >> 8) & 0xff;
  161. snd_pmac_burgundy_read_volume(chip, addr,
  162. ucontrol->value.integer.value, shift);
  163. return 0;
  164. }
  165. static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
  166. struct snd_ctl_elem_value *ucontrol)
  167. {
  168. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  169. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  170. int shift = (kcontrol->private_value >> 8) & 0xff;
  171. long nvoices[2];
  172. snd_pmac_burgundy_write_volume(chip, addr,
  173. ucontrol->value.integer.value, shift);
  174. snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift);
  175. return (nvoices[0] != ucontrol->value.integer.value[0] ||
  176. nvoices[1] != ucontrol->value.integer.value[1]);
  177. }
  178. #define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
  179. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
  180. .info = snd_pmac_burgundy_info_volume,\
  181. .get = snd_pmac_burgundy_get_volume,\
  182. .put = snd_pmac_burgundy_put_volume,\
  183. .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
  184. /*
  185. * Burgundy volume: 0 - 100, stereo, 2-byte reg
  186. */
  187. static void
  188. snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
  189. long *volume, int off)
  190. {
  191. int lvolume, rvolume;
  192. off |= off << 2;
  193. lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
  194. rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
  195. snd_pmac_burgundy_wcb(chip, address + off, lvolume);
  196. snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
  197. }
  198. static void
  199. snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
  200. long *volume, int off)
  201. {
  202. volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
  203. if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
  204. volume[0] -= BURGUNDY_VOLUME_OFFSET;
  205. else
  206. volume[0] = 0;
  207. volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
  208. if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
  209. volume[1] -= BURGUNDY_VOLUME_OFFSET;
  210. else
  211. volume[1] = 0;
  212. }
  213. static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
  214. struct snd_ctl_elem_info *uinfo)
  215. {
  216. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  217. uinfo->count = 2;
  218. uinfo->value.integer.min = 0;
  219. uinfo->value.integer.max = 100;
  220. return 0;
  221. }
  222. static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
  223. struct snd_ctl_elem_value *ucontrol)
  224. {
  225. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  226. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  227. int off = kcontrol->private_value & 0x300;
  228. snd_pmac_burgundy_read_volume_2b(chip, addr,
  229. ucontrol->value.integer.value, off);
  230. return 0;
  231. }
  232. static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
  233. struct snd_ctl_elem_value *ucontrol)
  234. {
  235. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  236. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  237. int off = kcontrol->private_value & 0x300;
  238. long nvoices[2];
  239. snd_pmac_burgundy_write_volume_2b(chip, addr,
  240. ucontrol->value.integer.value, off);
  241. snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off);
  242. return (nvoices[0] != ucontrol->value.integer.value[0] ||
  243. nvoices[1] != ucontrol->value.integer.value[1]);
  244. }
  245. #define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
  246. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
  247. .info = snd_pmac_burgundy_info_volume_2b,\
  248. .get = snd_pmac_burgundy_get_volume_2b,\
  249. .put = snd_pmac_burgundy_put_volume_2b,\
  250. .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
  251. /*
  252. * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
  253. */
  254. static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
  255. struct snd_ctl_elem_info *uinfo)
  256. {
  257. int stereo = (kcontrol->private_value >> 24) & 1;
  258. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  259. uinfo->count = stereo + 1;
  260. uinfo->value.integer.min = 0;
  261. uinfo->value.integer.max = 15;
  262. return 0;
  263. }
  264. static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
  265. struct snd_ctl_elem_value *ucontrol)
  266. {
  267. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  268. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  269. int stereo = (kcontrol->private_value >> 24) & 1;
  270. int atten = (kcontrol->private_value >> 25) & 1;
  271. int oval;
  272. oval = snd_pmac_burgundy_rcb(chip, addr);
  273. if (atten)
  274. oval = ~oval & 0xff;
  275. ucontrol->value.integer.value[0] = oval & 0xf;
  276. if (stereo)
  277. ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
  278. return 0;
  279. }
  280. static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
  281. struct snd_ctl_elem_value *ucontrol)
  282. {
  283. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  284. unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  285. int stereo = (kcontrol->private_value >> 24) & 1;
  286. int atten = (kcontrol->private_value >> 25) & 1;
  287. int oval, val;
  288. oval = snd_pmac_burgundy_rcb(chip, addr);
  289. if (atten)
  290. oval = ~oval & 0xff;
  291. val = ucontrol->value.integer.value[0];
  292. if (stereo)
  293. val |= ucontrol->value.integer.value[1] << 4;
  294. else
  295. val |= ucontrol->value.integer.value[0] << 4;
  296. if (atten)
  297. val = ~val & 0xff;
  298. snd_pmac_burgundy_wcb(chip, addr, val);
  299. return val != oval;
  300. }
  301. #define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
  302. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
  303. .info = snd_pmac_burgundy_info_gain,\
  304. .get = snd_pmac_burgundy_get_gain,\
  305. .put = snd_pmac_burgundy_put_gain,\
  306. .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
  307. /*
  308. * Burgundy switch: 0/1, mono/stereo, word reg
  309. */
  310. static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
  311. struct snd_ctl_elem_info *uinfo)
  312. {
  313. int stereo = (kcontrol->private_value >> 24) & 1;
  314. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  315. uinfo->count = stereo + 1;
  316. uinfo->value.integer.min = 0;
  317. uinfo->value.integer.max = 1;
  318. return 0;
  319. }
  320. static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
  321. struct snd_ctl_elem_value *ucontrol)
  322. {
  323. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  324. unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  325. int lmask = 1 << (kcontrol->private_value & 0xff);
  326. int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
  327. int stereo = (kcontrol->private_value >> 24) & 1;
  328. int val = snd_pmac_burgundy_rcw(chip, addr);
  329. ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
  330. if (stereo)
  331. ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
  332. return 0;
  333. }
  334. static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
  335. struct snd_ctl_elem_value *ucontrol)
  336. {
  337. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  338. unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  339. int lmask = 1 << (kcontrol->private_value & 0xff);
  340. int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
  341. int stereo = (kcontrol->private_value >> 24) & 1;
  342. int val, oval;
  343. oval = snd_pmac_burgundy_rcw(chip, addr);
  344. val = oval & ~(lmask | (stereo ? rmask : 0));
  345. if (ucontrol->value.integer.value[0])
  346. val |= lmask;
  347. if (stereo && ucontrol->value.integer.value[1])
  348. val |= rmask;
  349. snd_pmac_burgundy_wcw(chip, addr, val);
  350. return val != oval;
  351. }
  352. #define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
  353. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
  354. .info = snd_pmac_burgundy_info_switch_w,\
  355. .get = snd_pmac_burgundy_get_switch_w,\
  356. .put = snd_pmac_burgundy_put_switch_w,\
  357. .private_value = ((lbit) | ((rbit) << 8)\
  358. | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
  359. /*
  360. * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
  361. */
  362. static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
  363. struct snd_ctl_elem_info *uinfo)
  364. {
  365. int stereo = (kcontrol->private_value >> 24) & 1;
  366. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  367. uinfo->count = stereo + 1;
  368. uinfo->value.integer.min = 0;
  369. uinfo->value.integer.max = 1;
  370. return 0;
  371. }
  372. static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
  373. struct snd_ctl_elem_value *ucontrol)
  374. {
  375. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  376. unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  377. int lmask = kcontrol->private_value & 0xff;
  378. int rmask = (kcontrol->private_value >> 8) & 0xff;
  379. int stereo = (kcontrol->private_value >> 24) & 1;
  380. int val = snd_pmac_burgundy_rcb(chip, addr);
  381. ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
  382. if (stereo)
  383. ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
  384. return 0;
  385. }
  386. static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
  387. struct snd_ctl_elem_value *ucontrol)
  388. {
  389. struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  390. unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  391. int lmask = kcontrol->private_value & 0xff;
  392. int rmask = (kcontrol->private_value >> 8) & 0xff;
  393. int stereo = (kcontrol->private_value >> 24) & 1;
  394. int val, oval;
  395. oval = snd_pmac_burgundy_rcb(chip, addr);
  396. val = oval & ~(lmask | rmask);
  397. if (ucontrol->value.integer.value[0])
  398. val |= lmask;
  399. if (stereo && ucontrol->value.integer.value[1])
  400. val |= rmask;
  401. snd_pmac_burgundy_wcb(chip, addr, val);
  402. return val != oval;
  403. }
  404. #define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
  405. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
  406. .info = snd_pmac_burgundy_info_switch_b,\
  407. .get = snd_pmac_burgundy_get_switch_b,\
  408. .put = snd_pmac_burgundy_put_switch_b,\
  409. .private_value = ((lmask) | ((rmask) << 8)\
  410. | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
  411. /*
  412. * Burgundy mixers
  413. */
  414. static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] = {
  415. BURGUNDY_VOLUME_W("Master Playback Volume", 0,
  416. MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8),
  417. BURGUNDY_VOLUME_W("CD Capture Volume", 0,
  418. MASK_ADDR_BURGUNDY_VOLCD, 16),
  419. BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
  420. MASK_ADDR_BURGUNDY_VOLMIX01, 2),
  421. BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
  422. MASK_ADDR_BURGUNDY_VOLMIX23, 0),
  423. BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
  424. MASK_ADDR_BURGUNDY_GAINCD, 1, 0),
  425. BURGUNDY_SWITCH_W("Master Capture Switch", 0,
  426. MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0),
  427. BURGUNDY_SWITCH_W("CD Capture Switch", 0,
  428. MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1),
  429. BURGUNDY_SWITCH_W("CD Playback Switch", 0,
  430. MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1),
  431. /* BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
  432. * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
  433. * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
  434. * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
  435. * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
  436. * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
  437. * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
  438. * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
  439. */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
  440. MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0)
  441. };
  442. static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] = {
  443. BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
  444. MASK_ADDR_BURGUNDY_VOLLINE, 16),
  445. BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
  446. MASK_ADDR_BURGUNDY_VOLMIC, 16),
  447. BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
  448. MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
  449. BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
  450. MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
  451. BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
  452. MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
  453. BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
  454. MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
  455. BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
  456. MASK_ADDR_BURGUNDY_ATTENHP, 1, 1),
  457. BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
  458. MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1),
  459. BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
  460. MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
  461. BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
  462. MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1),
  463. BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
  464. MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
  465. BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
  466. MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1)
  467. };
  468. static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] = {
  469. BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
  470. MASK_ADDR_BURGUNDY_VOLMIC, 16),
  471. BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
  472. MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
  473. BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
  474. MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
  475. BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
  476. MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
  477. BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
  478. MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
  479. BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
  480. MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
  481. /* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
  482. * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
  483. };
  484. static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac =
  485. BURGUNDY_SWITCH_B("Master Playback Switch", 0,
  486. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  487. BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT,
  488. BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1);
  489. static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac =
  490. BURGUNDY_SWITCH_B("Master Playback Switch", 0,
  491. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  492. BURGUNDY_OUTPUT_INTERN
  493. | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
  494. static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac =
  495. BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
  496. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  497. BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
  498. static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac =
  499. BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
  500. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  501. BURGUNDY_OUTPUT_INTERN, 0, 0);
  502. static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac =
  503. BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
  504. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  505. BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1);
  506. static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac =
  507. BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
  508. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  509. BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
  510. static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac =
  511. BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
  512. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  513. BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1);
  514. #ifdef PMAC_SUPPORT_AUTOMUTE
  515. /*
  516. * auto-mute stuffs
  517. */
  518. static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
  519. {
  520. return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
  521. }
  522. static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
  523. {
  524. if (chip->auto_mute) {
  525. int imac = of_machine_is_compatible("iMac");
  526. int reg, oreg;
  527. reg = oreg = snd_pmac_burgundy_rcb(chip,
  528. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES);
  529. reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
  530. | BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
  531. : ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
  532. | BURGUNDY_OUTPUT_INTERN);
  533. if (snd_pmac_burgundy_detect_headphone(chip))
  534. reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
  535. : (BURGUNDY_OUTPUT_LEFT
  536. | BURGUNDY_OUTPUT_RIGHT);
  537. else
  538. reg |= imac ? (BURGUNDY_OUTPUT_LEFT
  539. | BURGUNDY_OUTPUT_RIGHT)
  540. : (BURGUNDY_OUTPUT_INTERN);
  541. if (do_notify && reg == oreg)
  542. return;
  543. snd_pmac_burgundy_wcb(chip,
  544. MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
  545. if (do_notify) {
  546. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  547. &chip->master_sw_ctl->id);
  548. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  549. &chip->speaker_sw_ctl->id);
  550. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  551. &chip->hp_detect_ctl->id);
  552. }
  553. }
  554. }
  555. #endif /* PMAC_SUPPORT_AUTOMUTE */
  556. /*
  557. * initialize burgundy
  558. */
  559. int snd_pmac_burgundy_init(struct snd_pmac *chip)
  560. {
  561. int imac = of_machine_is_compatible("iMac");
  562. int i, err;
  563. /* Checks to see the chip is alive and kicking */
  564. if ((in_le32(&chip->awacs->codec_ctrl) & MASK_ERRCODE) == 0xf0000) {
  565. printk(KERN_WARNING "pmac burgundy: disabled by MacOS :-(\n");
  566. return 1;
  567. }
  568. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES,
  569. DEF_BURGUNDY_OUTPUTENABLES);
  570. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  571. DEF_BURGUNDY_MORE_OUTPUTENABLES);
  572. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTSELECTS,
  573. DEF_BURGUNDY_OUTPUTSELECTS);
  574. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21,
  575. DEF_BURGUNDY_INPSEL21);
  576. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3,
  577. imac ? DEF_BURGUNDY_INPSEL3_IMAC
  578. : DEF_BURGUNDY_INPSEL3_PMAC);
  579. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD,
  580. DEF_BURGUNDY_GAINCD);
  581. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE,
  582. DEF_BURGUNDY_GAINLINE);
  583. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMIC,
  584. DEF_BURGUNDY_GAINMIC);
  585. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMODEM,
  586. DEF_BURGUNDY_GAINMODEM);
  587. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENSPEAKER,
  588. DEF_BURGUNDY_ATTENSPEAKER);
  589. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENLINEOUT,
  590. DEF_BURGUNDY_ATTENLINEOUT);
  591. snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENHP,
  592. DEF_BURGUNDY_ATTENHP);
  593. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_MASTER_VOLUME,
  594. DEF_BURGUNDY_MASTER_VOLUME);
  595. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLCD,
  596. DEF_BURGUNDY_VOLCD);
  597. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLLINE,
  598. DEF_BURGUNDY_VOLLINE);
  599. snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC,
  600. DEF_BURGUNDY_VOLMIC);
  601. if (chip->hp_stat_mask == 0) {
  602. /* set headphone-jack detection bit */
  603. if (imac)
  604. chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
  605. | BURGUNDY_HPDETECT_IMAC_LOWER
  606. | BURGUNDY_HPDETECT_IMAC_SIDE;
  607. else
  608. chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
  609. }
  610. /*
  611. * build burgundy mixers
  612. */
  613. strcpy(chip->card->mixername, "PowerMac Burgundy");
  614. for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) {
  615. err = snd_ctl_add(chip->card,
  616. snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip));
  617. if (err < 0)
  618. return err;
  619. }
  620. for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac)
  621. : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) {
  622. err = snd_ctl_add(chip->card,
  623. snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i]
  624. : &snd_pmac_burgundy_mixers_pmac[i], chip));
  625. if (err < 0)
  626. return err;
  627. }
  628. chip->master_sw_ctl = snd_ctl_new1(imac
  629. ? &snd_pmac_burgundy_master_sw_imac
  630. : &snd_pmac_burgundy_master_sw_pmac, chip);
  631. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  632. if (err < 0)
  633. return err;
  634. chip->master_sw_ctl = snd_ctl_new1(imac
  635. ? &snd_pmac_burgundy_line_sw_imac
  636. : &snd_pmac_burgundy_line_sw_pmac, chip);
  637. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  638. if (err < 0)
  639. return err;
  640. if (imac) {
  641. chip->master_sw_ctl = snd_ctl_new1(
  642. &snd_pmac_burgundy_hp_sw_imac, chip);
  643. err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  644. if (err < 0)
  645. return err;
  646. }
  647. chip->speaker_sw_ctl = snd_ctl_new1(imac
  648. ? &snd_pmac_burgundy_speaker_sw_imac
  649. : &snd_pmac_burgundy_speaker_sw_pmac, chip);
  650. err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  651. if (err < 0)
  652. return err;
  653. #ifdef PMAC_SUPPORT_AUTOMUTE
  654. err = snd_pmac_add_automute(chip);
  655. if (err < 0)
  656. return err;
  657. chip->detect_headphone = snd_pmac_burgundy_detect_headphone;
  658. chip->update_automute = snd_pmac_burgundy_update_automute;
  659. snd_pmac_burgundy_update_automute(chip, 0); /* update the status only */
  660. #endif
  661. return 0;
  662. }