delta.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile
  5. * Digigram VX442
  6. *
  7. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/driver.h>
  25. #include <asm/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/mutex.h>
  31. #include <sound/core.h>
  32. #include <sound/cs8427.h>
  33. #include <sound/asoundef.h>
  34. #include "ice1712.h"
  35. #include "delta.h"
  36. #define SND_CS8403
  37. #include <sound/cs8403.h>
  38. /*
  39. * CS8427 via SPI mode (for Audiophile), emulated I2C
  40. */
  41. /* send 8 bits */
  42. static void ap_cs8427_write_byte(struct snd_ice1712 *ice, unsigned char data, unsigned char tmp)
  43. {
  44. int idx;
  45. for (idx = 7; idx >= 0; idx--) {
  46. tmp &= ~(ICE1712_DELTA_AP_DOUT|ICE1712_DELTA_AP_CCLK);
  47. if (data & (1 << idx))
  48. tmp |= ICE1712_DELTA_AP_DOUT;
  49. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  50. udelay(5);
  51. tmp |= ICE1712_DELTA_AP_CCLK;
  52. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  53. udelay(5);
  54. }
  55. }
  56. /* read 8 bits */
  57. static unsigned char ap_cs8427_read_byte(struct snd_ice1712 *ice, unsigned char tmp)
  58. {
  59. unsigned char data = 0;
  60. int idx;
  61. for (idx = 7; idx >= 0; idx--) {
  62. tmp &= ~ICE1712_DELTA_AP_CCLK;
  63. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  64. udelay(5);
  65. if (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_DELTA_AP_DIN)
  66. data |= 1 << idx;
  67. tmp |= ICE1712_DELTA_AP_CCLK;
  68. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  69. udelay(5);
  70. }
  71. return data;
  72. }
  73. /* assert chip select */
  74. static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
  75. {
  76. unsigned char tmp;
  77. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  78. switch (ice->eeprom.subvendor) {
  79. case ICE1712_SUBDEVICE_DELTA1010LT:
  80. tmp &= ~ICE1712_DELTA_1010LT_CS;
  81. tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
  82. break;
  83. case ICE1712_SUBDEVICE_AUDIOPHILE:
  84. case ICE1712_SUBDEVICE_DELTA410:
  85. tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC;
  86. tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL;
  87. break;
  88. case ICE1712_SUBDEVICE_VX442:
  89. tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B;
  90. tmp &= ~ICE1712_VX442_CS_DIGITAL;
  91. break;
  92. }
  93. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  94. udelay(5);
  95. return tmp;
  96. }
  97. /* deassert chip select */
  98. static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
  99. {
  100. switch (ice->eeprom.subvendor) {
  101. case ICE1712_SUBDEVICE_DELTA1010LT:
  102. tmp &= ~ICE1712_DELTA_1010LT_CS;
  103. tmp |= ICE1712_DELTA_1010LT_CS_NONE;
  104. break;
  105. case ICE1712_SUBDEVICE_AUDIOPHILE:
  106. case ICE1712_SUBDEVICE_DELTA410:
  107. tmp |= ICE1712_DELTA_AP_CS_DIGITAL;
  108. break;
  109. case ICE1712_SUBDEVICE_VX442:
  110. tmp |= ICE1712_VX442_CS_DIGITAL;
  111. break;
  112. }
  113. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  114. }
  115. /* sequential write */
  116. static int ap_cs8427_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
  117. {
  118. struct snd_ice1712 *ice = device->bus->private_data;
  119. int res = count;
  120. unsigned char tmp;
  121. mutex_lock(&ice->gpio_mutex);
  122. tmp = ap_cs8427_codec_select(ice);
  123. ap_cs8427_write_byte(ice, (device->addr << 1) | 0, tmp); /* address + write mode */
  124. while (count-- > 0)
  125. ap_cs8427_write_byte(ice, *bytes++, tmp);
  126. ap_cs8427_codec_deassert(ice, tmp);
  127. mutex_unlock(&ice->gpio_mutex);
  128. return res;
  129. }
  130. /* sequential read */
  131. static int ap_cs8427_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
  132. {
  133. struct snd_ice1712 *ice = device->bus->private_data;
  134. int res = count;
  135. unsigned char tmp;
  136. mutex_lock(&ice->gpio_mutex);
  137. tmp = ap_cs8427_codec_select(ice);
  138. ap_cs8427_write_byte(ice, (device->addr << 1) | 1, tmp); /* address + read mode */
  139. while (count-- > 0)
  140. *bytes++ = ap_cs8427_read_byte(ice, tmp);
  141. ap_cs8427_codec_deassert(ice, tmp);
  142. mutex_unlock(&ice->gpio_mutex);
  143. return res;
  144. }
  145. static int ap_cs8427_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
  146. {
  147. if (addr == 0x10)
  148. return 1;
  149. return -ENOENT;
  150. }
  151. static struct snd_i2c_ops ap_cs8427_i2c_ops = {
  152. .sendbytes = ap_cs8427_sendbytes,
  153. .readbytes = ap_cs8427_readbytes,
  154. .probeaddr = ap_cs8427_probeaddr,
  155. };
  156. /*
  157. */
  158. static void snd_ice1712_delta_cs8403_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
  159. {
  160. unsigned char tmp, mask1, mask2;
  161. int idx;
  162. /* send byte to transmitter */
  163. mask1 = ICE1712_DELTA_SPDIF_OUT_STAT_CLOCK;
  164. mask2 = ICE1712_DELTA_SPDIF_OUT_STAT_DATA;
  165. mutex_lock(&ice->gpio_mutex);
  166. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  167. for (idx = 7; idx >= 0; idx--) {
  168. tmp &= ~(mask1 | mask2);
  169. if (bits & (1 << idx))
  170. tmp |= mask2;
  171. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  172. udelay(100);
  173. tmp |= mask1;
  174. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  175. udelay(100);
  176. }
  177. tmp &= ~mask1;
  178. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  179. mutex_unlock(&ice->gpio_mutex);
  180. }
  181. static void delta_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
  182. {
  183. snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
  184. }
  185. static int delta_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
  186. {
  187. unsigned int val;
  188. int change;
  189. val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
  190. spin_lock_irq(&ice->reg_lock);
  191. change = ice->spdif.cs8403_bits != val;
  192. ice->spdif.cs8403_bits = val;
  193. if (change && ice->playback_pro_substream == NULL) {
  194. spin_unlock_irq(&ice->reg_lock);
  195. snd_ice1712_delta_cs8403_spdif_write(ice, val);
  196. } else {
  197. spin_unlock_irq(&ice->reg_lock);
  198. }
  199. return change;
  200. }
  201. static void delta_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
  202. {
  203. snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
  204. }
  205. static int delta_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
  206. {
  207. unsigned int val;
  208. int change;
  209. val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
  210. spin_lock_irq(&ice->reg_lock);
  211. change = ice->spdif.cs8403_stream_bits != val;
  212. ice->spdif.cs8403_stream_bits = val;
  213. if (change && ice->playback_pro_substream != NULL) {
  214. spin_unlock_irq(&ice->reg_lock);
  215. snd_ice1712_delta_cs8403_spdif_write(ice, val);
  216. } else {
  217. spin_unlock_irq(&ice->reg_lock);
  218. }
  219. return change;
  220. }
  221. /*
  222. * AK4524 on Delta 44 and 66 to choose the chip mask
  223. */
  224. static void delta_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  225. {
  226. struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
  227. struct snd_ice1712 *ice = ak->private_data[0];
  228. snd_ice1712_save_gpio_status(ice);
  229. priv->cs_mask =
  230. priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
  231. ICE1712_DELTA_CODEC_CHIP_B;
  232. }
  233. /*
  234. * AK4524 on Delta1010LT to choose the chip address
  235. */
  236. static void delta1010lt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  237. {
  238. struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
  239. struct snd_ice1712 *ice = ak->private_data[0];
  240. snd_ice1712_save_gpio_status(ice);
  241. priv->cs_mask = ICE1712_DELTA_1010LT_CS;
  242. priv->cs_addr = chip << 4;
  243. }
  244. /*
  245. * AK4528 on VX442 to choose the chip mask
  246. */
  247. static void vx442_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  248. {
  249. struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
  250. struct snd_ice1712 *ice = ak->private_data[0];
  251. snd_ice1712_save_gpio_status(ice);
  252. priv->cs_mask =
  253. priv->cs_addr = chip == 0 ? ICE1712_VX442_CODEC_CHIP_A :
  254. ICE1712_VX442_CODEC_CHIP_B;
  255. }
  256. /*
  257. * change the DFS bit according rate for Delta1010
  258. */
  259. static void delta_1010_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
  260. {
  261. unsigned char tmp, tmp2;
  262. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  263. return;
  264. mutex_lock(&ice->gpio_mutex);
  265. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  266. tmp2 = tmp & ~ICE1712_DELTA_DFS;
  267. if (rate > 48000)
  268. tmp2 |= ICE1712_DELTA_DFS;
  269. if (tmp != tmp2)
  270. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp2);
  271. mutex_unlock(&ice->gpio_mutex);
  272. }
  273. /*
  274. * change the rate of AK4524 on Delta 44/66, AP, 1010LT
  275. */
  276. static void delta_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  277. {
  278. unsigned char tmp, tmp2;
  279. struct snd_ice1712 *ice = ak->private_data[0];
  280. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  281. return;
  282. /* check before reset ak4524 to avoid unnecessary clicks */
  283. mutex_lock(&ice->gpio_mutex);
  284. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  285. mutex_unlock(&ice->gpio_mutex);
  286. tmp2 = tmp & ~ICE1712_DELTA_DFS;
  287. if (rate > 48000)
  288. tmp2 |= ICE1712_DELTA_DFS;
  289. if (tmp == tmp2)
  290. return;
  291. /* do it again */
  292. snd_akm4xxx_reset(ak, 1);
  293. mutex_lock(&ice->gpio_mutex);
  294. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
  295. if (rate > 48000)
  296. tmp |= ICE1712_DELTA_DFS;
  297. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  298. mutex_unlock(&ice->gpio_mutex);
  299. snd_akm4xxx_reset(ak, 0);
  300. }
  301. /*
  302. * change the rate of AK4524 on VX442
  303. */
  304. static void vx442_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  305. {
  306. unsigned char val;
  307. val = (rate > 48000) ? 0x65 : 0x60;
  308. if (snd_akm4xxx_get(ak, 0, 0x02) != val ||
  309. snd_akm4xxx_get(ak, 1, 0x02) != val) {
  310. snd_akm4xxx_reset(ak, 1);
  311. snd_akm4xxx_write(ak, 0, 0x02, val);
  312. snd_akm4xxx_write(ak, 1, 0x02, val);
  313. snd_akm4xxx_reset(ak, 0);
  314. }
  315. }
  316. /*
  317. * SPDIF ops for Delta 1010, Dio, 66
  318. */
  319. /* open callback */
  320. static void delta_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
  321. {
  322. ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
  323. }
  324. /* set up */
  325. static void delta_setup_spdif(struct snd_ice1712 *ice, int rate)
  326. {
  327. unsigned long flags;
  328. unsigned int tmp;
  329. int change;
  330. spin_lock_irqsave(&ice->reg_lock, flags);
  331. tmp = ice->spdif.cs8403_stream_bits;
  332. if (tmp & 0x01) /* consumer */
  333. tmp &= (tmp & 0x01) ? ~0x06 : ~0x18;
  334. switch (rate) {
  335. case 32000: tmp |= (tmp & 0x01) ? 0x04 : 0x00; break;
  336. case 44100: tmp |= (tmp & 0x01) ? 0x00 : 0x10; break;
  337. case 48000: tmp |= (tmp & 0x01) ? 0x02 : 0x08; break;
  338. default: tmp |= (tmp & 0x01) ? 0x00 : 0x18; break;
  339. }
  340. change = ice->spdif.cs8403_stream_bits != tmp;
  341. ice->spdif.cs8403_stream_bits = tmp;
  342. spin_unlock_irqrestore(&ice->reg_lock, flags);
  343. if (change)
  344. snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
  345. snd_ice1712_delta_cs8403_spdif_write(ice, tmp);
  346. }
  347. #define snd_ice1712_delta1010lt_wordclock_status_info \
  348. snd_ctl_boolean_mono_info
  349. static int snd_ice1712_delta1010lt_wordclock_status_get(struct snd_kcontrol *kcontrol,
  350. struct snd_ctl_elem_value *ucontrol)
  351. {
  352. char reg = 0x10; // cs8427 receiver error register
  353. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  354. if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1)
  355. snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
  356. snd_i2c_readbytes(ice->cs8427, &reg, 1);
  357. ucontrol->value.integer.value[0] = (reg ? 1 : 0);
  358. return 0;
  359. }
  360. static struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_status __devinitdata =
  361. {
  362. .access = (SNDRV_CTL_ELEM_ACCESS_READ),
  363. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  364. .name = "Word Clock Status",
  365. .info = snd_ice1712_delta1010lt_wordclock_status_info,
  366. .get = snd_ice1712_delta1010lt_wordclock_status_get,
  367. };
  368. /*
  369. * initialize the chips on M-Audio cards
  370. */
  371. static struct snd_akm4xxx akm_audiophile __devinitdata = {
  372. .type = SND_AK4528,
  373. .num_adcs = 2,
  374. .num_dacs = 2,
  375. .ops = {
  376. .set_rate_val = delta_ak4524_set_rate_val
  377. }
  378. };
  379. static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = {
  380. .caddr = 2,
  381. .cif = 0,
  382. .data_mask = ICE1712_DELTA_AP_DOUT,
  383. .clk_mask = ICE1712_DELTA_AP_CCLK,
  384. .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
  385. .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
  386. .cs_none = 0,
  387. .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
  388. .mask_flags = 0,
  389. };
  390. static struct snd_akm4xxx akm_delta410 __devinitdata = {
  391. .type = SND_AK4529,
  392. .num_adcs = 2,
  393. .num_dacs = 8,
  394. .ops = {
  395. .set_rate_val = delta_ak4524_set_rate_val
  396. }
  397. };
  398. static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = {
  399. .caddr = 0,
  400. .cif = 0,
  401. .data_mask = ICE1712_DELTA_AP_DOUT,
  402. .clk_mask = ICE1712_DELTA_AP_CCLK,
  403. .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
  404. .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
  405. .cs_none = 0,
  406. .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
  407. .mask_flags = 0,
  408. };
  409. static struct snd_akm4xxx akm_delta1010lt __devinitdata = {
  410. .type = SND_AK4524,
  411. .num_adcs = 8,
  412. .num_dacs = 8,
  413. .ops = {
  414. .lock = delta1010lt_ak4524_lock,
  415. .set_rate_val = delta_ak4524_set_rate_val
  416. }
  417. };
  418. static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
  419. .caddr = 2,
  420. .cif = 0, /* the default level of the CIF pin from AK4524 */
  421. .data_mask = ICE1712_DELTA_1010LT_DOUT,
  422. .clk_mask = ICE1712_DELTA_1010LT_CCLK,
  423. .cs_mask = 0,
  424. .cs_addr = 0, /* set later */
  425. .cs_none = ICE1712_DELTA_1010LT_CS_NONE,
  426. .add_flags = 0,
  427. .mask_flags = 0,
  428. };
  429. static struct snd_akm4xxx akm_delta44 __devinitdata = {
  430. .type = SND_AK4524,
  431. .num_adcs = 4,
  432. .num_dacs = 4,
  433. .ops = {
  434. .lock = delta_ak4524_lock,
  435. .set_rate_val = delta_ak4524_set_rate_val
  436. }
  437. };
  438. static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = {
  439. .caddr = 2,
  440. .cif = 0, /* the default level of the CIF pin from AK4524 */
  441. .data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA,
  442. .clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK,
  443. .cs_mask = 0,
  444. .cs_addr = 0, /* set later */
  445. .cs_none = 0,
  446. .add_flags = 0,
  447. .mask_flags = 0,
  448. };
  449. static struct snd_akm4xxx akm_vx442 __devinitdata = {
  450. .type = SND_AK4524,
  451. .num_adcs = 4,
  452. .num_dacs = 4,
  453. .ops = {
  454. .lock = vx442_ak4524_lock,
  455. .set_rate_val = vx442_ak4524_set_rate_val
  456. }
  457. };
  458. static struct snd_ak4xxx_private akm_vx442_priv __devinitdata = {
  459. .caddr = 2,
  460. .cif = 0,
  461. .data_mask = ICE1712_VX442_DOUT,
  462. .clk_mask = ICE1712_VX442_CCLK,
  463. .cs_mask = 0,
  464. .cs_addr = 0, /* set later */
  465. .cs_none = 0,
  466. .add_flags = 0,
  467. .mask_flags = 0,
  468. };
  469. static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
  470. {
  471. int err;
  472. struct snd_akm4xxx *ak;
  473. /* determine I2C, DACs and ADCs */
  474. switch (ice->eeprom.subvendor) {
  475. case ICE1712_SUBDEVICE_AUDIOPHILE:
  476. ice->num_total_dacs = 2;
  477. ice->num_total_adcs = 2;
  478. break;
  479. case ICE1712_SUBDEVICE_DELTA410:
  480. ice->num_total_dacs = 8;
  481. ice->num_total_adcs = 2;
  482. break;
  483. case ICE1712_SUBDEVICE_DELTA44:
  484. case ICE1712_SUBDEVICE_DELTA66:
  485. ice->num_total_dacs = ice->omni ? 8 : 4;
  486. ice->num_total_adcs = ice->omni ? 8 : 4;
  487. break;
  488. case ICE1712_SUBDEVICE_DELTA1010:
  489. case ICE1712_SUBDEVICE_DELTA1010LT:
  490. case ICE1712_SUBDEVICE_MEDIASTATION:
  491. ice->num_total_dacs = 8;
  492. ice->num_total_adcs = 8;
  493. break;
  494. case ICE1712_SUBDEVICE_DELTADIO2496:
  495. ice->num_total_dacs = 4; /* two AK4324 codecs */
  496. break;
  497. case ICE1712_SUBDEVICE_VX442:
  498. ice->num_total_dacs = 4;
  499. ice->num_total_adcs = 4;
  500. break;
  501. }
  502. /* initialize spdif */
  503. switch (ice->eeprom.subvendor) {
  504. case ICE1712_SUBDEVICE_AUDIOPHILE:
  505. case ICE1712_SUBDEVICE_DELTA410:
  506. case ICE1712_SUBDEVICE_DELTA1010LT:
  507. case ICE1712_SUBDEVICE_VX442:
  508. if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
  509. snd_printk(KERN_ERR "unable to create I2C bus\n");
  510. return err;
  511. }
  512. ice->i2c->private_data = ice;
  513. ice->i2c->ops = &ap_cs8427_i2c_ops;
  514. if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
  515. return err;
  516. break;
  517. case ICE1712_SUBDEVICE_DELTA1010:
  518. case ICE1712_SUBDEVICE_MEDIASTATION:
  519. ice->gpio.set_pro_rate = delta_1010_set_rate_val;
  520. break;
  521. case ICE1712_SUBDEVICE_DELTADIO2496:
  522. ice->gpio.set_pro_rate = delta_1010_set_rate_val;
  523. /* fall thru */
  524. case ICE1712_SUBDEVICE_DELTA66:
  525. ice->spdif.ops.open = delta_open_spdif;
  526. ice->spdif.ops.setup_rate = delta_setup_spdif;
  527. ice->spdif.ops.default_get = delta_spdif_default_get;
  528. ice->spdif.ops.default_put = delta_spdif_default_put;
  529. ice->spdif.ops.stream_get = delta_spdif_stream_get;
  530. ice->spdif.ops.stream_put = delta_spdif_stream_put;
  531. /* Set spdif defaults */
  532. snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
  533. break;
  534. }
  535. /* no analog? */
  536. switch (ice->eeprom.subvendor) {
  537. case ICE1712_SUBDEVICE_DELTA1010:
  538. case ICE1712_SUBDEVICE_DELTADIO2496:
  539. case ICE1712_SUBDEVICE_MEDIASTATION:
  540. return 0;
  541. }
  542. /* second stage of initialization, analog parts and others */
  543. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  544. if (! ak)
  545. return -ENOMEM;
  546. ice->akm_codecs = 1;
  547. switch (ice->eeprom.subvendor) {
  548. case ICE1712_SUBDEVICE_AUDIOPHILE:
  549. err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
  550. break;
  551. case ICE1712_SUBDEVICE_DELTA410:
  552. err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
  553. break;
  554. case ICE1712_SUBDEVICE_DELTA1010LT:
  555. err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
  556. break;
  557. case ICE1712_SUBDEVICE_DELTA66:
  558. case ICE1712_SUBDEVICE_DELTA44:
  559. err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
  560. break;
  561. case ICE1712_SUBDEVICE_VX442:
  562. err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
  563. break;
  564. default:
  565. snd_BUG();
  566. return -EINVAL;
  567. }
  568. return err;
  569. }
  570. /*
  571. * additional controls for M-Audio cards
  572. */
  573. static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_select __devinitdata =
  574. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
  575. static struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_select __devinitdata =
  576. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 0, 0);
  577. static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_status __devinitdata =
  578. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
  579. static struct snd_kcontrol_new snd_ice1712_deltadio2496_spdif_in_select __devinitdata =
  580. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
  581. static struct snd_kcontrol_new snd_ice1712_delta_spdif_in_status __devinitdata =
  582. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
  583. static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
  584. {
  585. int err;
  586. /* 1010 and dio specific controls */
  587. switch (ice->eeprom.subvendor) {
  588. case ICE1712_SUBDEVICE_DELTA1010:
  589. case ICE1712_SUBDEVICE_MEDIASTATION:
  590. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice));
  591. if (err < 0)
  592. return err;
  593. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice));
  594. if (err < 0)
  595. return err;
  596. break;
  597. case ICE1712_SUBDEVICE_DELTADIO2496:
  598. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice));
  599. if (err < 0)
  600. return err;
  601. break;
  602. case ICE1712_SUBDEVICE_DELTA1010LT:
  603. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
  604. if (err < 0)
  605. return err;
  606. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_status, ice));
  607. if (err < 0)
  608. return err;
  609. break;
  610. }
  611. /* normal spdif controls */
  612. switch (ice->eeprom.subvendor) {
  613. case ICE1712_SUBDEVICE_DELTA1010:
  614. case ICE1712_SUBDEVICE_DELTADIO2496:
  615. case ICE1712_SUBDEVICE_DELTA66:
  616. case ICE1712_SUBDEVICE_MEDIASTATION:
  617. err = snd_ice1712_spdif_build_controls(ice);
  618. if (err < 0)
  619. return err;
  620. break;
  621. }
  622. /* spdif status in */
  623. switch (ice->eeprom.subvendor) {
  624. case ICE1712_SUBDEVICE_DELTA1010:
  625. case ICE1712_SUBDEVICE_DELTADIO2496:
  626. case ICE1712_SUBDEVICE_DELTA66:
  627. case ICE1712_SUBDEVICE_MEDIASTATION:
  628. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice));
  629. if (err < 0)
  630. return err;
  631. break;
  632. }
  633. /* ak4524 controls */
  634. switch (ice->eeprom.subvendor) {
  635. case ICE1712_SUBDEVICE_DELTA1010LT:
  636. case ICE1712_SUBDEVICE_AUDIOPHILE:
  637. case ICE1712_SUBDEVICE_DELTA410:
  638. case ICE1712_SUBDEVICE_DELTA44:
  639. case ICE1712_SUBDEVICE_DELTA66:
  640. case ICE1712_SUBDEVICE_VX442:
  641. err = snd_ice1712_akm4xxx_build_controls(ice);
  642. if (err < 0)
  643. return err;
  644. break;
  645. }
  646. return 0;
  647. }
  648. /* entry point */
  649. struct snd_ice1712_card_info snd_ice1712_delta_cards[] __devinitdata = {
  650. {
  651. .subvendor = ICE1712_SUBDEVICE_DELTA1010,
  652. .name = "M Audio Delta 1010",
  653. .model = "delta1010",
  654. .chip_init = snd_ice1712_delta_init,
  655. .build_controls = snd_ice1712_delta_add_controls,
  656. },
  657. {
  658. .subvendor = ICE1712_SUBDEVICE_DELTADIO2496,
  659. .name = "M Audio Delta DiO 2496",
  660. .model = "dio2496",
  661. .chip_init = snd_ice1712_delta_init,
  662. .build_controls = snd_ice1712_delta_add_controls,
  663. .no_mpu401 = 1,
  664. },
  665. {
  666. .subvendor = ICE1712_SUBDEVICE_DELTA66,
  667. .name = "M Audio Delta 66",
  668. .model = "delta66",
  669. .chip_init = snd_ice1712_delta_init,
  670. .build_controls = snd_ice1712_delta_add_controls,
  671. .no_mpu401 = 1,
  672. },
  673. {
  674. .subvendor = ICE1712_SUBDEVICE_DELTA44,
  675. .name = "M Audio Delta 44",
  676. .model = "delta44",
  677. .chip_init = snd_ice1712_delta_init,
  678. .build_controls = snd_ice1712_delta_add_controls,
  679. .no_mpu401 = 1,
  680. },
  681. {
  682. .subvendor = ICE1712_SUBDEVICE_AUDIOPHILE,
  683. .name = "M Audio Audiophile 24/96",
  684. .model = "audiophile",
  685. .chip_init = snd_ice1712_delta_init,
  686. .build_controls = snd_ice1712_delta_add_controls,
  687. },
  688. {
  689. .subvendor = ICE1712_SUBDEVICE_DELTA410,
  690. .name = "M Audio Delta 410",
  691. .model = "delta410",
  692. .chip_init = snd_ice1712_delta_init,
  693. .build_controls = snd_ice1712_delta_add_controls,
  694. },
  695. {
  696. .subvendor = ICE1712_SUBDEVICE_DELTA1010LT,
  697. .name = "M Audio Delta 1010LT",
  698. .model = "delta1010lt",
  699. .chip_init = snd_ice1712_delta_init,
  700. .build_controls = snd_ice1712_delta_add_controls,
  701. },
  702. {
  703. .subvendor = ICE1712_SUBDEVICE_VX442,
  704. .name = "Digigram VX442",
  705. .model = "vx442",
  706. .chip_init = snd_ice1712_delta_init,
  707. .build_controls = snd_ice1712_delta_add_controls,
  708. .no_mpu401 = 1,
  709. },
  710. {
  711. .subvendor = ICE1712_SUBDEVICE_MEDIASTATION,
  712. .name = "Lionstracs Mediastation",
  713. .model = "mediastation",
  714. .chip_init = snd_ice1712_delta_init,
  715. .build_controls = snd_ice1712_delta_add_controls,
  716. },
  717. { } /* terminator */
  718. };