hoontech.c 11 KB

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