burgundy.c 24 KB

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