delta.c 24 KB

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