hoontech.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 <linux/mutex.h>
  30. #include <sound/core.h>
  31. #include "ice1712.h"
  32. #include "hoontech.h"
  33. static void __devinit snd_ice1712_stdsp24_gpio_write(struct snd_ice1712 *ice, unsigned char byte)
  34. {
  35. byte |= ICE1712_STDSP24_CLOCK_BIT;
  36. udelay(100);
  37. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  38. byte &= ~ICE1712_STDSP24_CLOCK_BIT;
  39. udelay(100);
  40. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  41. byte |= ICE1712_STDSP24_CLOCK_BIT;
  42. udelay(100);
  43. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  44. }
  45. static void __devinit snd_ice1712_stdsp24_darear(struct snd_ice1712 *ice, int activate)
  46. {
  47. mutex_lock(&ice->gpio_mutex);
  48. ICE1712_STDSP24_0_DAREAR(ice->spec.hoontech.boxbits, activate);
  49. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  50. mutex_unlock(&ice->gpio_mutex);
  51. }
  52. static void __devinit snd_ice1712_stdsp24_mute(struct snd_ice1712 *ice, int activate)
  53. {
  54. mutex_lock(&ice->gpio_mutex);
  55. ICE1712_STDSP24_3_MUTE(ice->spec.hoontech.boxbits, activate);
  56. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  57. mutex_unlock(&ice->gpio_mutex);
  58. }
  59. static void __devinit snd_ice1712_stdsp24_insel(struct snd_ice1712 *ice, int activate)
  60. {
  61. mutex_lock(&ice->gpio_mutex);
  62. ICE1712_STDSP24_3_INSEL(ice->spec.hoontech.boxbits, activate);
  63. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  64. mutex_unlock(&ice->gpio_mutex);
  65. }
  66. static void __devinit snd_ice1712_stdsp24_box_channel(struct snd_ice1712 *ice, int box, int chn, int activate)
  67. {
  68. mutex_lock(&ice->gpio_mutex);
  69. /* select box */
  70. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, box);
  71. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  72. /* prepare for write */
  73. if (chn == 3)
  74. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 0);
  75. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, activate);
  76. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  77. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  78. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  79. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  80. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  81. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  82. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  83. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  84. udelay(100);
  85. if (chn == 3) {
  86. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 0);
  87. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  88. } else {
  89. switch (chn) {
  90. case 0: ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 0); break;
  91. case 1: ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 0); break;
  92. case 2: ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 0); break;
  93. }
  94. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  95. }
  96. udelay(100);
  97. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  98. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  99. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  100. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  101. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[1]);
  102. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  103. udelay(100);
  104. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, 0);
  105. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  106. mutex_unlock(&ice->gpio_mutex);
  107. }
  108. static void __devinit snd_ice1712_stdsp24_box_midi(struct snd_ice1712 *ice, int box, int master)
  109. {
  110. mutex_lock(&ice->gpio_mutex);
  111. /* select box */
  112. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, box);
  113. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[0]);
  114. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  115. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, master);
  116. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  117. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  118. udelay(100);
  119. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 0);
  120. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  121. mdelay(10);
  122. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  123. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[2]);
  124. mutex_unlock(&ice->gpio_mutex);
  125. }
  126. static void __devinit snd_ice1712_stdsp24_midi2(struct snd_ice1712 *ice, int activate)
  127. {
  128. mutex_lock(&ice->gpio_mutex);
  129. ICE1712_STDSP24_3_MIDI2(ice->spec.hoontech.boxbits, activate);
  130. snd_ice1712_stdsp24_gpio_write(ice, ice->spec.hoontech.boxbits[3]);
  131. mutex_unlock(&ice->gpio_mutex);
  132. }
  133. static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
  134. {
  135. int box, chn;
  136. ice->num_total_dacs = 8;
  137. ice->num_total_adcs = 8;
  138. ice->spec.hoontech.boxbits[0] =
  139. ice->spec.hoontech.boxbits[1] =
  140. ice->spec.hoontech.boxbits[2] =
  141. ice->spec.hoontech.boxbits[3] = 0; /* should be already */
  142. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 0);
  143. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 0, 1);
  144. ICE1712_STDSP24_0_BOX(ice->spec.hoontech.boxbits, 0);
  145. ICE1712_STDSP24_0_DAREAR(ice->spec.hoontech.boxbits, 0);
  146. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 1);
  147. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 1, 1);
  148. ICE1712_STDSP24_1_CHN1(ice->spec.hoontech.boxbits, 1);
  149. ICE1712_STDSP24_1_CHN2(ice->spec.hoontech.boxbits, 1);
  150. ICE1712_STDSP24_1_CHN3(ice->spec.hoontech.boxbits, 1);
  151. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 2);
  152. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 2, 1);
  153. ICE1712_STDSP24_2_CHN4(ice->spec.hoontech.boxbits, 1);
  154. ICE1712_STDSP24_2_MIDIIN(ice->spec.hoontech.boxbits, 1);
  155. ICE1712_STDSP24_2_MIDI1(ice->spec.hoontech.boxbits, 0);
  156. ICE1712_STDSP24_SET_ADDR(ice->spec.hoontech.boxbits, 3);
  157. ICE1712_STDSP24_CLOCK(ice->spec.hoontech.boxbits, 3, 1);
  158. ICE1712_STDSP24_3_MIDI2(ice->spec.hoontech.boxbits, 0);
  159. ICE1712_STDSP24_3_MUTE(ice->spec.hoontech.boxbits, 1);
  160. ICE1712_STDSP24_3_INSEL(ice->spec.hoontech.boxbits, 0);
  161. /* let's go - activate only functions in first box */
  162. ice->spec.hoontech.config = 0;
  163. /* ICE1712_STDSP24_MUTE |
  164. ICE1712_STDSP24_INSEL |
  165. ICE1712_STDSP24_DAREAR; */
  166. ice->spec.hoontech.boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
  167. ICE1712_STDSP24_BOX_CHN2 |
  168. ICE1712_STDSP24_BOX_CHN3 |
  169. ICE1712_STDSP24_BOX_CHN4 |
  170. ICE1712_STDSP24_BOX_MIDI1 |
  171. ICE1712_STDSP24_BOX_MIDI2;
  172. ice->spec.hoontech.boxconfig[1] =
  173. ice->spec.hoontech.boxconfig[2] =
  174. ice->spec.hoontech.boxconfig[3] = 0;
  175. snd_ice1712_stdsp24_darear(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_DAREAR) ? 1 : 0);
  176. snd_ice1712_stdsp24_mute(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_MUTE) ? 1 : 0);
  177. snd_ice1712_stdsp24_insel(ice, (ice->spec.hoontech.config & ICE1712_STDSP24_INSEL) ? 1 : 0);
  178. for (box = 0; box < 4; box++) {
  179. for (chn = 0; chn < 4; chn++)
  180. snd_ice1712_stdsp24_box_channel(ice, box, chn, (ice->spec.hoontech.boxconfig[box] & (1 << chn)) ? 1 : 0);
  181. snd_ice1712_stdsp24_box_midi(ice, box,
  182. (ice->spec.hoontech.boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0);
  183. if (ice->spec.hoontech.boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
  184. snd_ice1712_stdsp24_midi2(ice, 1);
  185. }
  186. return 0;
  187. }
  188. /*
  189. * AK4524 access
  190. */
  191. /* start callback for STDSP24 with modified hardware */
  192. static void stdsp24_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  193. {
  194. struct snd_ice1712 *ice = ak->private_data[0];
  195. unsigned char tmp;
  196. snd_ice1712_save_gpio_status(ice);
  197. tmp = ICE1712_STDSP24_SERIAL_DATA |
  198. ICE1712_STDSP24_SERIAL_CLOCK |
  199. ICE1712_STDSP24_AK4524_CS;
  200. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
  201. ice->gpio.direction | tmp);
  202. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
  203. }
  204. static int __devinit snd_ice1712_value_init(struct snd_ice1712 *ice)
  205. {
  206. /* Hoontech STDSP24 with modified hardware */
  207. static const struct snd_akm4xxx akm_stdsp24_mv __devinitdata = {
  208. .num_adcs = 2,
  209. .num_dacs = 2,
  210. .type = SND_AK4524,
  211. .ops = {
  212. .lock = stdsp24_ak4524_lock
  213. }
  214. };
  215. static const struct snd_ak4xxx_private akm_stdsp24_mv_priv __devinitdata = {
  216. .caddr = 2,
  217. .cif = 1, /* CIF high */
  218. .data_mask = ICE1712_STDSP24_SERIAL_DATA,
  219. .clk_mask = ICE1712_STDSP24_SERIAL_CLOCK,
  220. .cs_mask = ICE1712_STDSP24_AK4524_CS,
  221. .cs_addr = ICE1712_STDSP24_AK4524_CS,
  222. .cs_none = 0,
  223. .add_flags = 0,
  224. };
  225. int err;
  226. struct snd_akm4xxx *ak;
  227. /* set the analog DACs */
  228. ice->num_total_dacs = 2;
  229. /* set the analog ADCs */
  230. ice->num_total_adcs = 2;
  231. /* analog section */
  232. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  233. if (! ak)
  234. return -ENOMEM;
  235. ice->akm_codecs = 1;
  236. err = snd_ice1712_akm4xxx_init(ak, &akm_stdsp24_mv, &akm_stdsp24_mv_priv, ice);
  237. if (err < 0)
  238. return err;
  239. /* ak4524 controls */
  240. err = snd_ice1712_akm4xxx_build_controls(ice);
  241. if (err < 0)
  242. return err;
  243. return 0;
  244. }
  245. static int __devinit snd_ice1712_ez8_init(struct snd_ice1712 *ice)
  246. {
  247. ice->gpio.write_mask = ice->eeprom.gpiomask;
  248. ice->gpio.direction = ice->eeprom.gpiodir;
  249. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
  250. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
  251. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
  252. return 0;
  253. }
  254. /* entry point */
  255. const struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
  256. {
  257. .subvendor = ICE1712_SUBDEVICE_STDSP24,
  258. .name = "Hoontech SoundTrack Audio DSP24",
  259. .model = "dsp24",
  260. .chip_init = snd_ice1712_hoontech_init,
  261. },
  262. {
  263. .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
  264. .name = "Hoontech SoundTrack Audio DSP24 Value",
  265. .model = "dsp24_value",
  266. .chip_init = snd_ice1712_value_init,
  267. },
  268. {
  269. .subvendor = ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
  270. .name = "Hoontech STA DSP24 Media 7.1",
  271. .model = "dsp24_71",
  272. .chip_init = snd_ice1712_hoontech_init,
  273. },
  274. {
  275. .subvendor = ICE1712_SUBDEVICE_EVENT_EZ8, /* a dummy id */
  276. .name = "Event Electronics EZ8",
  277. .model = "ez8",
  278. .chip_init = snd_ice1712_ez8_init,
  279. },
  280. { } /* terminator */
  281. };