revo.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Lowlevel functions for M-Audio Revolution 7.1
  5. *
  6. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <asm/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <sound/core.h>
  30. #include "ice1712.h"
  31. #include "envy24ht.h"
  32. #include "revo.h"
  33. static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
  34. {
  35. /* assert PRST# to converters; MT05 bit 7 */
  36. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  37. mdelay(5);
  38. /* deassert PRST# */
  39. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  40. }
  41. /*
  42. * change the rate of envy24HT, AK4355 and AK4381
  43. */
  44. static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  45. {
  46. unsigned char old, tmp, dfs;
  47. int reg, shift;
  48. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  49. return;
  50. /* adjust DFS on codecs */
  51. if (rate > 96000)
  52. dfs = 2;
  53. else if (rate > 48000)
  54. dfs = 1;
  55. else
  56. dfs = 0;
  57. if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
  58. reg = 2;
  59. shift = 4;
  60. } else {
  61. reg = 1;
  62. shift = 3;
  63. }
  64. tmp = snd_akm4xxx_get(ak, 0, reg);
  65. old = (tmp >> shift) & 0x03;
  66. if (old == dfs)
  67. return;
  68. /* reset DFS */
  69. snd_akm4xxx_reset(ak, 1);
  70. tmp = snd_akm4xxx_get(ak, 0, reg);
  71. tmp &= ~(0x03 << shift);
  72. tmp |= dfs << shift;
  73. // snd_akm4xxx_write(ak, 0, reg, tmp);
  74. snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
  75. snd_akm4xxx_reset(ak, 0);
  76. }
  77. /*
  78. * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1)
  79. */
  80. static void revo_i2c_start(struct snd_i2c_bus *bus)
  81. {
  82. struct snd_ice1712 *ice = bus->private_data;
  83. snd_ice1712_save_gpio_status(ice);
  84. }
  85. static void revo_i2c_stop(struct snd_i2c_bus *bus)
  86. {
  87. struct snd_ice1712 *ice = bus->private_data;
  88. snd_ice1712_restore_gpio_status(ice);
  89. }
  90. static void revo_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
  91. {
  92. struct snd_ice1712 *ice = bus->private_data;
  93. unsigned int mask, val;
  94. val = 0;
  95. if (clock)
  96. val |= VT1724_REVO_I2C_CLOCK; /* write SCL */
  97. if (data)
  98. val |= VT1724_REVO_I2C_DATA; /* write SDA */
  99. mask = VT1724_REVO_I2C_CLOCK | VT1724_REVO_I2C_DATA;
  100. ice->gpio.direction &= ~mask;
  101. ice->gpio.direction |= val;
  102. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  103. snd_ice1712_gpio_set_mask(ice, ~mask);
  104. }
  105. static void revo_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
  106. {
  107. struct snd_ice1712 *ice = bus->private_data;
  108. unsigned int val = 0;
  109. if (clk)
  110. val |= VT1724_REVO_I2C_CLOCK;
  111. if (data)
  112. val |= VT1724_REVO_I2C_DATA;
  113. snd_ice1712_gpio_write_bits(ice,
  114. VT1724_REVO_I2C_DATA |
  115. VT1724_REVO_I2C_CLOCK, val);
  116. udelay(5);
  117. }
  118. static int revo_i2c_getdata(struct snd_i2c_bus *bus, int ack)
  119. {
  120. struct snd_ice1712 *ice = bus->private_data;
  121. int bit;
  122. if (ack)
  123. udelay(5);
  124. bit = snd_ice1712_gpio_read_bits(ice, VT1724_REVO_I2C_DATA) ? 1 : 0;
  125. return bit;
  126. }
  127. static struct snd_i2c_bit_ops revo51_bit_ops = {
  128. .start = revo_i2c_start,
  129. .stop = revo_i2c_stop,
  130. .direction = revo_i2c_direction,
  131. .setlines = revo_i2c_setlines,
  132. .getdata = revo_i2c_getdata,
  133. };
  134. static int revo51_i2c_init(struct snd_ice1712 *ice,
  135. struct snd_pt2258 *pt)
  136. {
  137. int err;
  138. /* create the I2C bus */
  139. err = snd_i2c_bus_create(ice->card, "ICE1724 GPIO6", NULL, &ice->i2c);
  140. if (err < 0)
  141. return err;
  142. ice->i2c->private_data = ice;
  143. ice->i2c->hw_ops.bit = &revo51_bit_ops;
  144. /* create the I2C device */
  145. err = snd_i2c_device_create(ice->i2c, "PT2258", 0x40,
  146. &ice->spec.revo51.dev);
  147. if (err < 0)
  148. return err;
  149. pt->card = ice->card;
  150. pt->i2c_bus = ice->i2c;
  151. pt->i2c_dev = ice->spec.revo51.dev;
  152. ice->spec.revo51.pt2258 = pt;
  153. snd_pt2258_reset(pt);
  154. return 0;
  155. }
  156. /*
  157. * initialize the chips on M-Audio Revolution cards
  158. */
  159. #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
  160. static struct snd_akm4xxx_dac_channel revo71_front[] = {
  161. AK_DAC("PCM Playback Volume", 2)
  162. };
  163. static struct snd_akm4xxx_dac_channel revo71_surround[] = {
  164. AK_DAC("PCM Center Playback Volume", 1),
  165. AK_DAC("PCM LFE Playback Volume", 1),
  166. AK_DAC("PCM Side Playback Volume", 2),
  167. AK_DAC("PCM Rear Playback Volume", 2),
  168. };
  169. static struct snd_akm4xxx_dac_channel revo51_dac[] = {
  170. AK_DAC("PCM Playback Volume", 2),
  171. AK_DAC("PCM Center Playback Volume", 1),
  172. AK_DAC("PCM LFE Playback Volume", 1),
  173. AK_DAC("PCM Rear Playback Volume", 2),
  174. };
  175. static const char *revo51_adc_input_names[] = {
  176. "Mic",
  177. "Line",
  178. "CD",
  179. NULL
  180. };
  181. static struct snd_akm4xxx_adc_channel revo51_adc[] = {
  182. {
  183. .name = "PCM Capture Volume",
  184. .switch_name = "PCM Capture Switch",
  185. .num_channels = 2,
  186. .input_names = revo51_adc_input_names
  187. },
  188. };
  189. static struct snd_akm4xxx akm_revo_front __devinitdata = {
  190. .type = SND_AK4381,
  191. .num_dacs = 2,
  192. .ops = {
  193. .set_rate_val = revo_set_rate_val
  194. },
  195. .dac_info = revo71_front,
  196. };
  197. static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
  198. .caddr = 1,
  199. .cif = 0,
  200. .data_mask = VT1724_REVO_CDOUT,
  201. .clk_mask = VT1724_REVO_CCLK,
  202. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  203. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
  204. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  205. .add_flags = VT1724_REVO_CCLK, /* high at init */
  206. .mask_flags = 0,
  207. };
  208. static struct snd_akm4xxx akm_revo_surround __devinitdata = {
  209. .type = SND_AK4355,
  210. .idx_offset = 1,
  211. .num_dacs = 6,
  212. .ops = {
  213. .set_rate_val = revo_set_rate_val
  214. },
  215. .dac_info = revo71_surround,
  216. };
  217. static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
  218. .caddr = 3,
  219. .cif = 0,
  220. .data_mask = VT1724_REVO_CDOUT,
  221. .clk_mask = VT1724_REVO_CCLK,
  222. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  223. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  224. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  225. .add_flags = VT1724_REVO_CCLK, /* high at init */
  226. .mask_flags = 0,
  227. };
  228. static struct snd_akm4xxx akm_revo51 __devinitdata = {
  229. .type = SND_AK4358,
  230. .num_dacs = 6,
  231. .ops = {
  232. .set_rate_val = revo_set_rate_val
  233. },
  234. .dac_info = revo51_dac,
  235. };
  236. static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
  237. .caddr = 2,
  238. .cif = 0,
  239. .data_mask = VT1724_REVO_CDOUT,
  240. .clk_mask = VT1724_REVO_CCLK,
  241. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  242. .cs_addr = VT1724_REVO_CS1,
  243. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  244. .add_flags = VT1724_REVO_CCLK, /* high at init */
  245. .mask_flags = 0,
  246. };
  247. static struct snd_akm4xxx akm_revo51_adc __devinitdata = {
  248. .type = SND_AK5365,
  249. .num_adcs = 2,
  250. .adc_info = revo51_adc,
  251. };
  252. static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = {
  253. .caddr = 2,
  254. .cif = 0,
  255. .data_mask = VT1724_REVO_CDOUT,
  256. .clk_mask = VT1724_REVO_CCLK,
  257. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  258. .cs_addr = VT1724_REVO_CS0,
  259. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  260. .add_flags = VT1724_REVO_CCLK, /* high at init */
  261. .mask_flags = 0,
  262. };
  263. static struct snd_pt2258 ptc_revo51_volume;
  264. static int __devinit revo_init(struct snd_ice1712 *ice)
  265. {
  266. struct snd_akm4xxx *ak;
  267. int err;
  268. /* determine I2C, DACs and ADCs */
  269. switch (ice->eeprom.subvendor) {
  270. case VT1724_SUBDEVICE_REVOLUTION71:
  271. ice->num_total_dacs = 8;
  272. ice->num_total_adcs = 2;
  273. ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
  274. break;
  275. case VT1724_SUBDEVICE_REVOLUTION51:
  276. ice->num_total_dacs = 6;
  277. ice->num_total_adcs = 2;
  278. break;
  279. default:
  280. snd_BUG();
  281. return -EINVAL;
  282. }
  283. /* second stage of initialization, analog parts and others */
  284. ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
  285. if (! ak)
  286. return -ENOMEM;
  287. ice->akm_codecs = 2;
  288. switch (ice->eeprom.subvendor) {
  289. case VT1724_SUBDEVICE_REVOLUTION71:
  290. ice->akm_codecs = 2;
  291. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
  292. return err;
  293. if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
  294. return err;
  295. /* unmute all codecs */
  296. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  297. break;
  298. case VT1724_SUBDEVICE_REVOLUTION51:
  299. ice->akm_codecs = 2;
  300. err = snd_ice1712_akm4xxx_init(ak, &akm_revo51,
  301. &akm_revo51_priv, ice);
  302. if (err < 0)
  303. return err;
  304. err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo51_adc,
  305. &akm_revo51_adc_priv, ice);
  306. if (err < 0)
  307. return err;
  308. err = revo51_i2c_init(ice, &ptc_revo51_volume);
  309. if (err < 0)
  310. return err;
  311. /* unmute all codecs */
  312. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
  313. VT1724_REVO_MUTE);
  314. break;
  315. }
  316. return 0;
  317. }
  318. static int __devinit revo_add_controls(struct snd_ice1712 *ice)
  319. {
  320. int err;
  321. switch (ice->eeprom.subvendor) {
  322. case VT1724_SUBDEVICE_REVOLUTION71:
  323. err = snd_ice1712_akm4xxx_build_controls(ice);
  324. if (err < 0)
  325. return err;
  326. break;
  327. case VT1724_SUBDEVICE_REVOLUTION51:
  328. err = snd_ice1712_akm4xxx_build_controls(ice);
  329. if (err < 0)
  330. return err;
  331. err = snd_pt2258_build_controls(ice->spec.revo51.pt2258);
  332. if (err < 0)
  333. return err;
  334. break;
  335. }
  336. return 0;
  337. }
  338. /* entry point */
  339. struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
  340. {
  341. .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
  342. .name = "M Audio Revolution-7.1",
  343. .model = "revo71",
  344. .chip_init = revo_init,
  345. .build_controls = revo_add_controls,
  346. },
  347. {
  348. .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
  349. .name = "M Audio Revolution-5.1",
  350. .model = "revo51",
  351. .chip_init = revo_init,
  352. .build_controls = revo_add_controls,
  353. },
  354. { } /* terminator */
  355. };