burgundy.c 24 KB

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