delta.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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 const 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. dev_err(ice->card->dev,
  376. "unable to send register 0x%x byte to CS8427\n", reg);
  377. snd_i2c_readbytes(ice->cs8427, &reg, 1);
  378. ucontrol->value.integer.value[0] = (reg & CS8427_UNLOCK) ? 1 : 0;
  379. return 0;
  380. }
  381. static const struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_status =
  382. {
  383. .access = (SNDRV_CTL_ELEM_ACCESS_READ),
  384. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  385. .name = "Word Clock Status",
  386. .info = snd_ice1712_delta1010lt_wordclock_status_info,
  387. .get = snd_ice1712_delta1010lt_wordclock_status_get,
  388. };
  389. /*
  390. * initialize the chips on M-Audio cards
  391. */
  392. static const struct snd_akm4xxx akm_audiophile = {
  393. .type = SND_AK4528,
  394. .num_adcs = 2,
  395. .num_dacs = 2,
  396. .ops = {
  397. .set_rate_val = delta_ak4524_set_rate_val
  398. }
  399. };
  400. static const struct snd_ak4xxx_private akm_audiophile_priv = {
  401. .caddr = 2,
  402. .cif = 0,
  403. .data_mask = ICE1712_DELTA_AP_DOUT,
  404. .clk_mask = ICE1712_DELTA_AP_CCLK,
  405. .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
  406. .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
  407. .cs_none = 0,
  408. .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
  409. .mask_flags = 0,
  410. };
  411. static const struct snd_akm4xxx akm_delta410 = {
  412. .type = SND_AK4529,
  413. .num_adcs = 2,
  414. .num_dacs = 8,
  415. .ops = {
  416. .set_rate_val = delta_ak4524_set_rate_val
  417. }
  418. };
  419. static const struct snd_ak4xxx_private akm_delta410_priv = {
  420. .caddr = 0,
  421. .cif = 0,
  422. .data_mask = ICE1712_DELTA_AP_DOUT,
  423. .clk_mask = ICE1712_DELTA_AP_CCLK,
  424. .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
  425. .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
  426. .cs_none = 0,
  427. .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
  428. .mask_flags = 0,
  429. };
  430. static const struct snd_akm4xxx akm_delta1010lt = {
  431. .type = SND_AK4524,
  432. .num_adcs = 8,
  433. .num_dacs = 8,
  434. .ops = {
  435. .lock = delta1010lt_ak4524_lock,
  436. .set_rate_val = delta_ak4524_set_rate_val
  437. }
  438. };
  439. static const struct snd_ak4xxx_private akm_delta1010lt_priv = {
  440. .caddr = 2,
  441. .cif = 0, /* the default level of the CIF pin from AK4524 */
  442. .data_mask = ICE1712_DELTA_1010LT_DOUT,
  443. .clk_mask = ICE1712_DELTA_1010LT_CCLK,
  444. .cs_mask = 0,
  445. .cs_addr = 0, /* set later */
  446. .cs_none = ICE1712_DELTA_1010LT_CS_NONE,
  447. .add_flags = 0,
  448. .mask_flags = 0,
  449. };
  450. static const struct snd_akm4xxx akm_delta66e = {
  451. .type = SND_AK4524,
  452. .num_adcs = 4,
  453. .num_dacs = 4,
  454. .ops = {
  455. .lock = delta66e_ak4524_lock,
  456. .set_rate_val = delta_ak4524_set_rate_val
  457. }
  458. };
  459. static const struct snd_ak4xxx_private akm_delta66e_priv = {
  460. .caddr = 2,
  461. .cif = 0, /* the default level of the CIF pin from AK4524 */
  462. .data_mask = ICE1712_DELTA_66E_DOUT,
  463. .clk_mask = ICE1712_DELTA_66E_CCLK,
  464. .cs_mask = 0,
  465. .cs_addr = 0, /* set later */
  466. .cs_none = 0,
  467. .add_flags = 0,
  468. .mask_flags = 0,
  469. };
  470. static const struct snd_akm4xxx akm_delta44 = {
  471. .type = SND_AK4524,
  472. .num_adcs = 4,
  473. .num_dacs = 4,
  474. .ops = {
  475. .lock = delta_ak4524_lock,
  476. .set_rate_val = delta_ak4524_set_rate_val
  477. }
  478. };
  479. static const struct snd_ak4xxx_private akm_delta44_priv = {
  480. .caddr = 2,
  481. .cif = 0, /* the default level of the CIF pin from AK4524 */
  482. .data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA,
  483. .clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK,
  484. .cs_mask = 0,
  485. .cs_addr = 0, /* set later */
  486. .cs_none = 0,
  487. .add_flags = 0,
  488. .mask_flags = 0,
  489. };
  490. static const struct snd_akm4xxx akm_vx442 = {
  491. .type = SND_AK4524,
  492. .num_adcs = 4,
  493. .num_dacs = 4,
  494. .ops = {
  495. .lock = vx442_ak4524_lock,
  496. .set_rate_val = vx442_ak4524_set_rate_val
  497. }
  498. };
  499. static const struct snd_ak4xxx_private akm_vx442_priv = {
  500. .caddr = 2,
  501. .cif = 0,
  502. .data_mask = ICE1712_VX442_DOUT,
  503. .clk_mask = ICE1712_VX442_CCLK,
  504. .cs_mask = 0,
  505. .cs_addr = 0, /* set later */
  506. .cs_none = 0,
  507. .add_flags = 0,
  508. .mask_flags = 0,
  509. };
  510. #ifdef CONFIG_PM_SLEEP
  511. static int snd_ice1712_delta_resume(struct snd_ice1712 *ice)
  512. {
  513. unsigned char akm_img_bak[AK4XXX_IMAGE_SIZE];
  514. unsigned char akm_vol_bak[AK4XXX_IMAGE_SIZE];
  515. /* init spdif */
  516. switch (ice->eeprom.subvendor) {
  517. case ICE1712_SUBDEVICE_AUDIOPHILE:
  518. case ICE1712_SUBDEVICE_DELTA410:
  519. case ICE1712_SUBDEVICE_DELTA1010E:
  520. case ICE1712_SUBDEVICE_DELTA1010LT:
  521. case ICE1712_SUBDEVICE_VX442:
  522. case ICE1712_SUBDEVICE_DELTA66E:
  523. snd_cs8427_init(ice->i2c, ice->cs8427);
  524. break;
  525. case ICE1712_SUBDEVICE_DELTA1010:
  526. case ICE1712_SUBDEVICE_MEDIASTATION:
  527. /* nothing */
  528. break;
  529. case ICE1712_SUBDEVICE_DELTADIO2496:
  530. case ICE1712_SUBDEVICE_DELTA66:
  531. /* Set spdif defaults */
  532. snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
  533. break;
  534. }
  535. /* init codec and restore registers */
  536. if (ice->akm_codecs) {
  537. memcpy(akm_img_bak, ice->akm->images, sizeof(akm_img_bak));
  538. memcpy(akm_vol_bak, ice->akm->volumes, sizeof(akm_vol_bak));
  539. snd_akm4xxx_init(ice->akm);
  540. memcpy(ice->akm->images, akm_img_bak, sizeof(akm_img_bak));
  541. memcpy(ice->akm->volumes, akm_vol_bak, sizeof(akm_vol_bak));
  542. snd_akm4xxx_reset(ice->akm, 0);
  543. }
  544. return 0;
  545. }
  546. static int snd_ice1712_delta_suspend(struct snd_ice1712 *ice)
  547. {
  548. if (ice->akm_codecs) /* reset & mute codec */
  549. snd_akm4xxx_reset(ice->akm, 1);
  550. return 0;
  551. }
  552. #endif
  553. static int snd_ice1712_delta_init(struct snd_ice1712 *ice)
  554. {
  555. int err;
  556. struct snd_akm4xxx *ak;
  557. unsigned char tmp;
  558. if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA1010 &&
  559. ice->eeprom.gpiodir == 0x7b)
  560. ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA1010E;
  561. if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA66 &&
  562. ice->eeprom.gpiodir == 0xfb)
  563. ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA66E;
  564. /* determine I2C, DACs and ADCs */
  565. switch (ice->eeprom.subvendor) {
  566. case ICE1712_SUBDEVICE_AUDIOPHILE:
  567. ice->num_total_dacs = 2;
  568. ice->num_total_adcs = 2;
  569. break;
  570. case ICE1712_SUBDEVICE_DELTA410:
  571. ice->num_total_dacs = 8;
  572. ice->num_total_adcs = 2;
  573. break;
  574. case ICE1712_SUBDEVICE_DELTA44:
  575. case ICE1712_SUBDEVICE_DELTA66:
  576. ice->num_total_dacs = ice->omni ? 8 : 4;
  577. ice->num_total_adcs = ice->omni ? 8 : 4;
  578. break;
  579. case ICE1712_SUBDEVICE_DELTA1010:
  580. case ICE1712_SUBDEVICE_DELTA1010E:
  581. case ICE1712_SUBDEVICE_DELTA1010LT:
  582. case ICE1712_SUBDEVICE_MEDIASTATION:
  583. case ICE1712_SUBDEVICE_EDIROLDA2496:
  584. ice->num_total_dacs = 8;
  585. ice->num_total_adcs = 8;
  586. break;
  587. case ICE1712_SUBDEVICE_DELTADIO2496:
  588. ice->num_total_dacs = 4; /* two AK4324 codecs */
  589. break;
  590. case ICE1712_SUBDEVICE_VX442:
  591. case ICE1712_SUBDEVICE_DELTA66E: /* omni not supported yet */
  592. ice->num_total_dacs = 4;
  593. ice->num_total_adcs = 4;
  594. break;
  595. }
  596. #ifdef CONFIG_PM_SLEEP
  597. ice->pm_resume = snd_ice1712_delta_resume;
  598. ice->pm_suspend = snd_ice1712_delta_suspend;
  599. ice->pm_suspend_enabled = 1;
  600. #endif
  601. /* initialize the SPI clock to high */
  602. tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  603. tmp |= ICE1712_DELTA_AP_CCLK;
  604. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
  605. udelay(5);
  606. /* initialize spdif */
  607. switch (ice->eeprom.subvendor) {
  608. case ICE1712_SUBDEVICE_AUDIOPHILE:
  609. case ICE1712_SUBDEVICE_DELTA410:
  610. case ICE1712_SUBDEVICE_DELTA1010E:
  611. case ICE1712_SUBDEVICE_DELTA1010LT:
  612. case ICE1712_SUBDEVICE_VX442:
  613. case ICE1712_SUBDEVICE_DELTA66E:
  614. if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
  615. dev_err(ice->card->dev, "unable to create I2C bus\n");
  616. return err;
  617. }
  618. ice->i2c->private_data = ice;
  619. ice->i2c->ops = &ap_cs8427_i2c_ops;
  620. if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
  621. return err;
  622. break;
  623. case ICE1712_SUBDEVICE_DELTA1010:
  624. case ICE1712_SUBDEVICE_MEDIASTATION:
  625. ice->gpio.set_pro_rate = delta_1010_set_rate_val;
  626. break;
  627. case ICE1712_SUBDEVICE_DELTADIO2496:
  628. ice->gpio.set_pro_rate = delta_1010_set_rate_val;
  629. /* fall thru */
  630. case ICE1712_SUBDEVICE_DELTA66:
  631. ice->spdif.ops.open = delta_open_spdif;
  632. ice->spdif.ops.setup_rate = delta_setup_spdif;
  633. ice->spdif.ops.default_get = delta_spdif_default_get;
  634. ice->spdif.ops.default_put = delta_spdif_default_put;
  635. ice->spdif.ops.stream_get = delta_spdif_stream_get;
  636. ice->spdif.ops.stream_put = delta_spdif_stream_put;
  637. /* Set spdif defaults */
  638. snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
  639. break;
  640. }
  641. /* no analog? */
  642. switch (ice->eeprom.subvendor) {
  643. case ICE1712_SUBDEVICE_DELTA1010:
  644. case ICE1712_SUBDEVICE_DELTA1010E:
  645. case ICE1712_SUBDEVICE_DELTADIO2496:
  646. case ICE1712_SUBDEVICE_MEDIASTATION:
  647. return 0;
  648. }
  649. /* second stage of initialization, analog parts and others */
  650. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  651. if (! ak)
  652. return -ENOMEM;
  653. ice->akm_codecs = 1;
  654. switch (ice->eeprom.subvendor) {
  655. case ICE1712_SUBDEVICE_AUDIOPHILE:
  656. err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
  657. break;
  658. case ICE1712_SUBDEVICE_DELTA410:
  659. err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
  660. break;
  661. case ICE1712_SUBDEVICE_DELTA1010LT:
  662. case ICE1712_SUBDEVICE_EDIROLDA2496:
  663. err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
  664. break;
  665. case ICE1712_SUBDEVICE_DELTA66:
  666. case ICE1712_SUBDEVICE_DELTA44:
  667. err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
  668. break;
  669. case ICE1712_SUBDEVICE_VX442:
  670. err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
  671. break;
  672. case ICE1712_SUBDEVICE_DELTA66E:
  673. err = snd_ice1712_akm4xxx_init(ak, &akm_delta66e, &akm_delta66e_priv, ice);
  674. break;
  675. default:
  676. snd_BUG();
  677. return -EINVAL;
  678. }
  679. return err;
  680. }
  681. /*
  682. * additional controls for M-Audio cards
  683. */
  684. static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_select =
  685. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
  686. static struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_select =
  687. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 0, 0);
  688. static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_status =
  689. 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);
  690. static struct snd_kcontrol_new snd_ice1712_deltadio2496_spdif_in_select =
  691. ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
  692. static struct snd_kcontrol_new snd_ice1712_delta_spdif_in_status =
  693. 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);
  694. static int snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
  695. {
  696. int err;
  697. /* 1010 and dio specific controls */
  698. switch (ice->eeprom.subvendor) {
  699. case ICE1712_SUBDEVICE_DELTA1010:
  700. case ICE1712_SUBDEVICE_MEDIASTATION:
  701. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice));
  702. if (err < 0)
  703. return err;
  704. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice));
  705. if (err < 0)
  706. return err;
  707. break;
  708. case ICE1712_SUBDEVICE_DELTADIO2496:
  709. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice));
  710. if (err < 0)
  711. return err;
  712. break;
  713. case ICE1712_SUBDEVICE_DELTA1010E:
  714. case ICE1712_SUBDEVICE_DELTA1010LT:
  715. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
  716. if (err < 0)
  717. return err;
  718. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_status, ice));
  719. if (err < 0)
  720. return err;
  721. break;
  722. }
  723. /* normal spdif controls */
  724. switch (ice->eeprom.subvendor) {
  725. case ICE1712_SUBDEVICE_DELTA1010:
  726. case ICE1712_SUBDEVICE_DELTADIO2496:
  727. case ICE1712_SUBDEVICE_DELTA66:
  728. case ICE1712_SUBDEVICE_MEDIASTATION:
  729. err = snd_ice1712_spdif_build_controls(ice);
  730. if (err < 0)
  731. return err;
  732. break;
  733. }
  734. /* spdif status in */
  735. switch (ice->eeprom.subvendor) {
  736. case ICE1712_SUBDEVICE_DELTA1010:
  737. case ICE1712_SUBDEVICE_DELTADIO2496:
  738. case ICE1712_SUBDEVICE_DELTA66:
  739. case ICE1712_SUBDEVICE_MEDIASTATION:
  740. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice));
  741. if (err < 0)
  742. return err;
  743. break;
  744. }
  745. /* ak4524 controls */
  746. switch (ice->eeprom.subvendor) {
  747. case ICE1712_SUBDEVICE_DELTA1010LT:
  748. case ICE1712_SUBDEVICE_AUDIOPHILE:
  749. case ICE1712_SUBDEVICE_DELTA410:
  750. case ICE1712_SUBDEVICE_DELTA44:
  751. case ICE1712_SUBDEVICE_DELTA66:
  752. case ICE1712_SUBDEVICE_VX442:
  753. case ICE1712_SUBDEVICE_DELTA66E:
  754. case ICE1712_SUBDEVICE_EDIROLDA2496:
  755. err = snd_ice1712_akm4xxx_build_controls(ice);
  756. if (err < 0)
  757. return err;
  758. break;
  759. }
  760. return 0;
  761. }
  762. /* entry point */
  763. struct snd_ice1712_card_info snd_ice1712_delta_cards[] = {
  764. {
  765. .subvendor = ICE1712_SUBDEVICE_DELTA1010,
  766. .name = "M Audio Delta 1010",
  767. .model = "delta1010",
  768. .chip_init = snd_ice1712_delta_init,
  769. .build_controls = snd_ice1712_delta_add_controls,
  770. },
  771. {
  772. .subvendor = ICE1712_SUBDEVICE_DELTADIO2496,
  773. .name = "M Audio Delta DiO 2496",
  774. .model = "dio2496",
  775. .chip_init = snd_ice1712_delta_init,
  776. .build_controls = snd_ice1712_delta_add_controls,
  777. .no_mpu401 = 1,
  778. },
  779. {
  780. .subvendor = ICE1712_SUBDEVICE_DELTA66,
  781. .name = "M Audio Delta 66",
  782. .model = "delta66",
  783. .chip_init = snd_ice1712_delta_init,
  784. .build_controls = snd_ice1712_delta_add_controls,
  785. .no_mpu401 = 1,
  786. },
  787. {
  788. .subvendor = ICE1712_SUBDEVICE_DELTA44,
  789. .name = "M Audio Delta 44",
  790. .model = "delta44",
  791. .chip_init = snd_ice1712_delta_init,
  792. .build_controls = snd_ice1712_delta_add_controls,
  793. .no_mpu401 = 1,
  794. },
  795. {
  796. .subvendor = ICE1712_SUBDEVICE_AUDIOPHILE,
  797. .name = "M Audio Audiophile 24/96",
  798. .model = "audiophile",
  799. .chip_init = snd_ice1712_delta_init,
  800. .build_controls = snd_ice1712_delta_add_controls,
  801. },
  802. {
  803. .subvendor = ICE1712_SUBDEVICE_DELTA410,
  804. .name = "M Audio Delta 410",
  805. .model = "delta410",
  806. .chip_init = snd_ice1712_delta_init,
  807. .build_controls = snd_ice1712_delta_add_controls,
  808. },
  809. {
  810. .subvendor = ICE1712_SUBDEVICE_DELTA1010LT,
  811. .name = "M Audio Delta 1010LT",
  812. .model = "delta1010lt",
  813. .chip_init = snd_ice1712_delta_init,
  814. .build_controls = snd_ice1712_delta_add_controls,
  815. },
  816. {
  817. .subvendor = ICE1712_SUBDEVICE_VX442,
  818. .name = "Digigram VX442",
  819. .model = "vx442",
  820. .chip_init = snd_ice1712_delta_init,
  821. .build_controls = snd_ice1712_delta_add_controls,
  822. .no_mpu401 = 1,
  823. },
  824. {
  825. .subvendor = ICE1712_SUBDEVICE_MEDIASTATION,
  826. .name = "Lionstracs Mediastation",
  827. .model = "mediastation",
  828. .chip_init = snd_ice1712_delta_init,
  829. .build_controls = snd_ice1712_delta_add_controls,
  830. },
  831. {
  832. .subvendor = ICE1712_SUBDEVICE_EDIROLDA2496,
  833. .name = "Edirol DA2496",
  834. .model = "da2496",
  835. .chip_init = snd_ice1712_delta_init,
  836. .build_controls = snd_ice1712_delta_add_controls,
  837. },
  838. { } /* terminator */
  839. };