hoontech.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Lowlevel functions for Hoontech STDSP24
  5. *
  6. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.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 <asm/io.h>
  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 "ice1712.h"
  31. #include "hoontech.h"
  32. /* Hoontech-specific setting */
  33. struct hoontech_spec {
  34. unsigned char boxbits[4];
  35. unsigned int config;
  36. unsigned short boxconfig[4];
  37. };
  38. static void __devinit snd_ice1712_stdsp24_gpio_write(struct snd_ice1712 *ice, unsigned char byte)
  39. {
  40. byte |= ICE1712_STDSP24_CLOCK_BIT;
  41. udelay(100);
  42. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  43. byte &= ~ICE1712_STDSP24_CLOCK_BIT;
  44. udelay(100);
  45. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  46. byte |= ICE1712_STDSP24_CLOCK_BIT;
  47. udelay(100);
  48. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
  49. }
  50. static void __devinit snd_ice1712_stdsp24_darear(struct snd_ice1712 *ice, int activate)
  51. {
  52. struct hoontech_spec *spec = ice->spec;
  53. mutex_lock(&ice->gpio_mutex);
  54. ICE1712_STDSP24_0_DAREAR(spec->boxbits, activate);
  55. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
  56. mutex_unlock(&ice->gpio_mutex);
  57. }
  58. static void __devinit snd_ice1712_stdsp24_mute(struct snd_ice1712 *ice, int activate)
  59. {
  60. struct hoontech_spec *spec = ice->spec;
  61. mutex_lock(&ice->gpio_mutex);
  62. ICE1712_STDSP24_3_MUTE(spec->boxbits, activate);
  63. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
  64. mutex_unlock(&ice->gpio_mutex);
  65. }
  66. static void __devinit snd_ice1712_stdsp24_insel(struct snd_ice1712 *ice, int activate)
  67. {
  68. struct hoontech_spec *spec = ice->spec;
  69. mutex_lock(&ice->gpio_mutex);
  70. ICE1712_STDSP24_3_INSEL(spec->boxbits, activate);
  71. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
  72. mutex_unlock(&ice->gpio_mutex);
  73. }
  74. static void __devinit snd_ice1712_stdsp24_box_channel(struct snd_ice1712 *ice, int box, int chn, int activate)
  75. {
  76. struct hoontech_spec *spec = ice->spec;
  77. mutex_lock(&ice->gpio_mutex);
  78. /* select box */
  79. ICE1712_STDSP24_0_BOX(spec->boxbits, box);
  80. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
  81. /* prepare for write */
  82. if (chn == 3)
  83. ICE1712_STDSP24_2_CHN4(spec->boxbits, 0);
  84. ICE1712_STDSP24_2_MIDI1(spec->boxbits, activate);
  85. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  86. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
  87. ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
  88. ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
  89. ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
  90. ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
  91. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
  92. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  93. udelay(100);
  94. if (chn == 3) {
  95. ICE1712_STDSP24_2_CHN4(spec->boxbits, 0);
  96. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  97. } else {
  98. switch (chn) {
  99. case 0: ICE1712_STDSP24_1_CHN1(spec->boxbits, 0); break;
  100. case 1: ICE1712_STDSP24_1_CHN2(spec->boxbits, 0); break;
  101. case 2: ICE1712_STDSP24_1_CHN3(spec->boxbits, 0); break;
  102. }
  103. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
  104. }
  105. udelay(100);
  106. ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
  107. ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
  108. ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
  109. ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
  110. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
  111. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  112. udelay(100);
  113. ICE1712_STDSP24_2_MIDI1(spec->boxbits, 0);
  114. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  115. mutex_unlock(&ice->gpio_mutex);
  116. }
  117. static void __devinit snd_ice1712_stdsp24_box_midi(struct snd_ice1712 *ice, int box, int master)
  118. {
  119. struct hoontech_spec *spec = ice->spec;
  120. mutex_lock(&ice->gpio_mutex);
  121. /* select box */
  122. ICE1712_STDSP24_0_BOX(spec->boxbits, box);
  123. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
  124. ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
  125. ICE1712_STDSP24_2_MIDI1(spec->boxbits, master);
  126. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  127. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
  128. udelay(100);
  129. ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 0);
  130. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  131. mdelay(10);
  132. ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
  133. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
  134. mutex_unlock(&ice->gpio_mutex);
  135. }
  136. static void __devinit snd_ice1712_stdsp24_midi2(struct snd_ice1712 *ice, int activate)
  137. {
  138. struct hoontech_spec *spec = ice->spec;
  139. mutex_lock(&ice->gpio_mutex);
  140. ICE1712_STDSP24_3_MIDI2(spec->boxbits, activate);
  141. snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
  142. mutex_unlock(&ice->gpio_mutex);
  143. }
  144. static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
  145. {
  146. struct hoontech_spec *spec;
  147. int box, chn;
  148. ice->num_total_dacs = 8;
  149. ice->num_total_adcs = 8;
  150. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  151. if (!spec)
  152. return -ENOMEM;
  153. ice->spec = spec;
  154. ICE1712_STDSP24_SET_ADDR(spec->boxbits, 0);
  155. ICE1712_STDSP24_CLOCK(spec->boxbits, 0, 1);
  156. ICE1712_STDSP24_0_BOX(spec->boxbits, 0);
  157. ICE1712_STDSP24_0_DAREAR(spec->boxbits, 0);
  158. ICE1712_STDSP24_SET_ADDR(spec->boxbits, 1);
  159. ICE1712_STDSP24_CLOCK(spec->boxbits, 1, 1);
  160. ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
  161. ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
  162. ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
  163. ICE1712_STDSP24_SET_ADDR(spec->boxbits, 2);
  164. ICE1712_STDSP24_CLOCK(spec->boxbits, 2, 1);
  165. ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
  166. ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
  167. ICE1712_STDSP24_2_MIDI1(spec->boxbits, 0);
  168. ICE1712_STDSP24_SET_ADDR(spec->boxbits, 3);
  169. ICE1712_STDSP24_CLOCK(spec->boxbits, 3, 1);
  170. ICE1712_STDSP24_3_MIDI2(spec->boxbits, 0);
  171. ICE1712_STDSP24_3_MUTE(spec->boxbits, 1);
  172. ICE1712_STDSP24_3_INSEL(spec->boxbits, 0);
  173. /* let's go - activate only functions in first box */
  174. spec->config = 0;
  175. /* ICE1712_STDSP24_MUTE |
  176. ICE1712_STDSP24_INSEL |
  177. ICE1712_STDSP24_DAREAR; */
  178. /* These boxconfigs have caused problems in the past.
  179. * The code is not optimal, but should now enable a working config to
  180. * be achieved.
  181. * ** MIDI IN can only be configured on one box **
  182. * ICE1712_STDSP24_BOX_MIDI1 needs to be set for that box.
  183. * Tests on a ADAC2000 box suggest the box config flags do not
  184. * work as would be expected, and the inputs are crossed.
  185. * Setting ICE1712_STDSP24_BOX_MIDI1 and ICE1712_STDSP24_BOX_MIDI2
  186. * on the same box connects MIDI-In to both 401 uarts; both outputs
  187. * are then active on all boxes.
  188. * The default config here sets up everything on the first box.
  189. * Alan Horstmann 5.2.2008
  190. */
  191. spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
  192. ICE1712_STDSP24_BOX_CHN2 |
  193. ICE1712_STDSP24_BOX_CHN3 |
  194. ICE1712_STDSP24_BOX_CHN4 |
  195. ICE1712_STDSP24_BOX_MIDI1 |
  196. ICE1712_STDSP24_BOX_MIDI2;
  197. spec->boxconfig[1] =
  198. spec->boxconfig[2] =
  199. spec->boxconfig[3] = 0;
  200. snd_ice1712_stdsp24_darear(ice,
  201. (spec->config & ICE1712_STDSP24_DAREAR) ? 1 : 0);
  202. snd_ice1712_stdsp24_mute(ice,
  203. (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
  204. snd_ice1712_stdsp24_insel(ice,
  205. (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
  206. for (box = 0; box < 4; box++) {
  207. if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
  208. snd_ice1712_stdsp24_midi2(ice, 1);
  209. for (chn = 0; chn < 4; chn++)
  210. snd_ice1712_stdsp24_box_channel(ice, box, chn,
  211. (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
  212. if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1)
  213. snd_ice1712_stdsp24_box_midi(ice, box, 1);
  214. }
  215. return 0;
  216. }
  217. /*
  218. * AK4524 access
  219. */
  220. /* start callback for STDSP24 with modified hardware */
  221. static void stdsp24_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  222. {
  223. struct snd_ice1712 *ice = ak->private_data[0];
  224. unsigned char tmp;
  225. snd_ice1712_save_gpio_status(ice);
  226. tmp = ICE1712_STDSP24_SERIAL_DATA |
  227. ICE1712_STDSP24_SERIAL_CLOCK |
  228. ICE1712_STDSP24_AK4524_CS;
  229. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
  230. ice->gpio.direction | tmp);
  231. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
  232. }
  233. static int __devinit snd_ice1712_value_init(struct snd_ice1712 *ice)
  234. {
  235. /* Hoontech STDSP24 with modified hardware */
  236. static struct snd_akm4xxx akm_stdsp24_mv __devinitdata = {
  237. .num_adcs = 2,
  238. .num_dacs = 2,
  239. .type = SND_AK4524,
  240. .ops = {
  241. .lock = stdsp24_ak4524_lock
  242. }
  243. };
  244. static struct snd_ak4xxx_private akm_stdsp24_mv_priv __devinitdata = {
  245. .caddr = 2,
  246. .cif = 1, /* CIF high */
  247. .data_mask = ICE1712_STDSP24_SERIAL_DATA,
  248. .clk_mask = ICE1712_STDSP24_SERIAL_CLOCK,
  249. .cs_mask = ICE1712_STDSP24_AK4524_CS,
  250. .cs_addr = ICE1712_STDSP24_AK4524_CS,
  251. .cs_none = 0,
  252. .add_flags = 0,
  253. };
  254. int err;
  255. struct snd_akm4xxx *ak;
  256. /* set the analog DACs */
  257. ice->num_total_dacs = 2;
  258. /* set the analog ADCs */
  259. ice->num_total_adcs = 2;
  260. /* analog section */
  261. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  262. if (! ak)
  263. return -ENOMEM;
  264. ice->akm_codecs = 1;
  265. err = snd_ice1712_akm4xxx_init(ak, &akm_stdsp24_mv, &akm_stdsp24_mv_priv, ice);
  266. if (err < 0)
  267. return err;
  268. /* ak4524 controls */
  269. err = snd_ice1712_akm4xxx_build_controls(ice);
  270. if (err < 0)
  271. return err;
  272. return 0;
  273. }
  274. static int __devinit snd_ice1712_ez8_init(struct snd_ice1712 *ice)
  275. {
  276. ice->gpio.write_mask = ice->eeprom.gpiomask;
  277. ice->gpio.direction = ice->eeprom.gpiodir;
  278. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
  279. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
  280. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
  281. return 0;
  282. }
  283. /* entry point */
  284. struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
  285. {
  286. .subvendor = ICE1712_SUBDEVICE_STDSP24,
  287. .name = "Hoontech SoundTrack Audio DSP24",
  288. .model = "dsp24",
  289. .chip_init = snd_ice1712_hoontech_init,
  290. .mpu401_1_name = "MIDI-1 Hoontech/STA DSP24",
  291. .mpu401_2_name = "MIDI-2 Hoontech/STA DSP24",
  292. },
  293. {
  294. .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
  295. .name = "Hoontech SoundTrack Audio DSP24 Value",
  296. .model = "dsp24_value",
  297. .chip_init = snd_ice1712_value_init,
  298. },
  299. {
  300. .subvendor = ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
  301. .name = "Hoontech STA DSP24 Media 7.1",
  302. .model = "dsp24_71",
  303. .chip_init = snd_ice1712_hoontech_init,
  304. },
  305. {
  306. .subvendor = ICE1712_SUBDEVICE_EVENT_EZ8, /* a dummy id */
  307. .name = "Event Electronics EZ8",
  308. .model = "ez8",
  309. .chip_init = snd_ice1712_ez8_init,
  310. },
  311. { } /* terminator */
  312. };