hoontech.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Lowlevel functions for Hoontech STDSP24
  5. *
  6. * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <asm/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <sound/core.h>
  30. #include "ice1712.h"
  31. #include "hoontech.h"
  32. static void __devinit snd_ice1712_stdsp24_gpio_write(struct snd_ice1712 *ice, unsigned char byte)
  33. {
  34. byte |= ICE1712_STDSP24_CLOCK_BIT;
  35. udelay(100);
  36. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  37. byte &= ~ICE1712_STDSP24_CLOCK_BIT;
  38. udelay(100);
  39. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  40. byte |= ICE1712_STDSP24_CLOCK_BIT;
  41. udelay(100);
  42. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  43. }
  44. static void __devinit snd_ice1712_stdsp24_darear(struct snd_ice1712 *ice, int activate)
  45. {
  46. down(&ice->gpio_mutex);
  47. ICE1712_STDSP24_0_DAREAR(ice->spec.hoontech.boxbits, activate);
  48. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  49. up(&ice->gpio_mutex);
  50. }
  51. static void __devinit snd_ice1712_stdsp24_mute(struct snd_ice1712 *ice, int activate)
  52. {
  53. down(&ice->gpio_mutex);
  54. ICE1712_STDSP24_3_MUTE(ice->spec.hoontech.boxbits, activate);
  55. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  56. up(&ice->gpio_mutex);
  57. }
  58. static void __devinit snd_ice1712_stdsp24_insel(struct snd_ice1712 *ice, int activate)
  59. {
  60. down(&ice->gpio_mutex);
  61. ICE1712_STDSP24_3_INSEL(ice->spec.hoontech.boxbits, activate);
  62. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  63. up(&ice->gpio_mutex);
  64. }
  65. static void __devinit snd_ice1712_stdsp24_box_channel(struct snd_ice1712 *ice, int box, int chn, int activate)
  66. {
  67. down(&ice->gpio_mutex);
  68. /* select box */
  69. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, box);
  70. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  71. /* prepare for write */
  72. if (chn == 3)
  73. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 0);
  74. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, activate);
  75. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  76. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  77. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  78. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  79. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  80. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  81. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  82. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  83. udelay(100);
  84. if (chn == 3) {
  85. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 0);
  86. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  87. } else {
  88. switch (chn) {
  89. case 0: ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 0); break;
  90. case 1: ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 0); break;
  91. case 2: ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 0); break;
  92. }
  93. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  94. }
  95. udelay(100);
  96. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  97. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  98. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  99. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  100. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  101. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  102. udelay(100);
  103. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, 0);
  104. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  105. up(&ice->gpio_mutex);
  106. }
  107. static void __devinit snd_ice1712_stdsp24_box_midi(struct snd_ice1712 *ice, int box, int master)
  108. {
  109. down(&ice->gpio_mutex);
  110. /* select box */
  111. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, box);
  112. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  113. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  114. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, master);
  115. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  116. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  117. udelay(100);
  118. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 0);
  119. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  120. mdelay(10);
  121. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  122. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  123. up(&ice->gpio_mutex);
  124. }
  125. static void __devinit snd_ice1712_stdsp24_midi2(struct snd_ice1712 *ice, int activate)
  126. {
  127. down(&ice->gpio_mutex);
  128. ICE1712_STDSP24_3_MIDI2(ice->spec.hoontech.boxbits, activate);
  129. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  130. up(&ice->gpio_mutex);
  131. }
  132. static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
  133. {
  134. int box, chn;
  135. ice->num_total_dacs = 8;
  136. ice->num_total_adcs = 8;
  137. ice->spec.hoontech.boxbits[0] =
  138. ice->spec.hoontech.boxbits[1] =
  139. ice->spec.hoontech.boxbits[2] =
  140. ice->spec.hoontech.boxbits[3] = 0; /* should be already */
  141. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 0);
  142. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 0, 1);
  143. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, 0);
  144. ICE1712_STDSP24_0_DAREAR(ice->spec.hoontech.boxbits, 0);
  145. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 1);
  146. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 1, 1);
  147. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  148. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  149. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  150. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 2);
  151. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 2, 1);
  152. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  153. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  154. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, 0);
  155. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 3);
  156. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 3, 1);
  157. ICE1712_STDSP24_3_MIDI2(ice->spec.hoontech.boxbits, 0);
  158. ICE1712_STDSP24_3_MUTE(ice->spec.hoontech.boxbits, 1);
  159. ICE1712_STDSP24_3_INSEL(ice->spec.hoontech.boxbits, 0);
  160. /* let's go - activate only functions in first box */
  161. ice->spec.hoontech.config = 0;
  162. /* ICE1712_STDSP24_MUTE |
  163. ICE1712_STDSP24_INSEL |
  164. ICE1712_STDSP24_DAREAR; */
  165. ice->spec.hoontech.boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
  166. ICE1712_STDSP24_BOX_CHN2 |
  167. ICE1712_STDSP24_BOX_CHN3 |
  168. ICE1712_STDSP24_BOX_CHN4 |
  169. ICE1712_STDSP24_BOX_MIDI1 |
  170. ICE1712_STDSP24_BOX_MIDI2;
  171. ice->spec.hoontech.boxconfig[1] =
  172. ice->spec.hoontech.boxconfig[2] =
  173. ice->spec.hoontech.boxconfig[3] = 0;
  174. snd_ice1712_stdsp24_darear(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_DAREAR) ? 1 : 0);
  175. snd_ice1712_stdsp24_mute(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_MUTE) ? 1 : 0);
  176. snd_ice1712_stdsp24_insel(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_INSEL) ? 1 : 0);
  177. for (box = 0; box < 4; box++) {
  178. for (chn = 0; chn < 4; chn++)
  179. snd_ice1712_stdsp24_box_channel(ice, box, chn, (ice->spec.hoontech.boxconfig[box] & (1 << chn)) ? 1 : 0);
  180. snd_ice1712_stdsp24_box_midi(ice, box,
  181. (ice->spec.hoontech.boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0);
  182. if (ice->spec.hoontech.boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
  183. snd_ice1712_stdsp24_midi2(ice, 1);
  184. }
  185. return 0;
  186. }
  187. /*
  188. * AK4524 access
  189. */
  190. /* start callback for STDSP24 with modified hardware */
  191. static void stdsp24_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  192. {
  193. struct snd_ice1712 *ice = ak->private_data[0];
  194. unsigned char tmp;
  195. snd_ice1712_save_gpio_status(ice);
  196. tmp = ICE1712_STDSP24_SERIAL_DATA |
  197. ICE1712_STDSP24_SERIAL_CLOCK |
  198. ICE1712_STDSP24_AK4524_CS;
  199. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
  200. ice->gpio.direction | tmp);
  201. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
  202. }
  203. static int __devinit snd_ice1712_value_init(struct snd_ice1712 *ice)
  204. {
  205. /* Hoontech STDSP24 with modified hardware */
  206. static struct snd_akm4xxx akm_stdsp24_mv __devinitdata = {
  207. .num_adcs = 2,
  208. .num_dacs = 2,
  209. .type = SND_AK4524,
  210. .ops = {
  211. .lock = stdsp24_ak4524_lock
  212. }
  213. };
  214. static struct snd_ak4xxx_private akm_stdsp24_mv_priv __devinitdata = {
  215. .caddr = 2,
  216. .cif = 1, /* CIF high */
  217. .data_mask = ICE1712_STDSP24_SERIAL_DATA,
  218. .clk_mask = ICE1712_STDSP24_SERIAL_CLOCK,
  219. .cs_mask = ICE1712_STDSP24_AK4524_CS,
  220. .cs_addr = ICE1712_STDSP24_AK4524_CS,
  221. .cs_none = 0,
  222. .add_flags = 0,
  223. };
  224. int err;
  225. struct snd_akm4xxx *ak;
  226. /* set the analog DACs */
  227. ice->num_total_dacs = 2;
  228. /* set the analog ADCs */
  229. ice->num_total_adcs = 2;
  230. /* analog section */
  231. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  232. if (! ak)
  233. return -ENOMEM;
  234. ice->akm_codecs = 1;
  235. err = snd_ice1712_akm4xxx_init(ak, &akm_stdsp24_mv, &akm_stdsp24_mv_priv, ice);
  236. if (err < 0)
  237. return err;
  238. /* ak4524 controls */
  239. err = snd_ice1712_akm4xxx_build_controls(ice);
  240. if (err < 0)
  241. return err;
  242. return 0;
  243. }
  244. static int __devinit snd_ice1712_ez8_init(struct snd_ice1712 *ice)
  245. {
  246. ice->gpio.write_mask = ice->eeprom.gpiomask;
  247. ice->gpio.direction = ice->eeprom.gpiodir;
  248. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
  249. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
  250. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
  251. return 0;
  252. }
  253. /* entry point */
  254. struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
  255. {
  256. .subvendor = ICE1712_SUBDEVICE_STDSP24,
  257. .name = "Hoontech SoundTrack Audio DSP24",
  258. .model = "dsp24",
  259. .chip_init = snd_ice1712_hoontech_init,
  260. },
  261. {
  262. .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
  263. .name = "Hoontech SoundTrack Audio DSP24 Value",
  264. .model = "dsp24_value",
  265. .chip_init = snd_ice1712_value_init,
  266. },
  267. {
  268. .subvendor = ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
  269. .name = "Hoontech STA DSP24 Media 7.1",
  270. .model = "dsp24_71",
  271. .chip_init = snd_ice1712_hoontech_init,
  272. },
  273. {
  274. .subvendor = ICE1712_SUBDEVICE_EVENT_EZ8, /* a dummy id */
  275. .name = "Event Electronics EZ8",
  276. .model = "ez8",
  277. .chip_init = snd_ice1712_ez8_init,
  278. },
  279. { } /* terminator */
  280. };