hoontech.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 hoontech_init(struct snd_ice1712 *ice, bool staudio)
  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. if (staudio)
  174. spec->config = ICE1712_STDSP24_MUTE;
  175. else
  176. spec->config = 0;
  177. /* ICE1712_STDSP24_MUTE |
  178. ICE1712_STDSP24_INSEL |
  179. ICE1712_STDSP24_DAREAR; */
  180. /* These boxconfigs have caused problems in the past.
  181. * The code is not optimal, but should now enable a working config to
  182. * be achieved.
  183. * ** MIDI IN can only be configured on one box **
  184. * ICE1712_STDSP24_BOX_MIDI1 needs to be set for that box.
  185. * Tests on a ADAC2000 box suggest the box config flags do not
  186. * work as would be expected, and the inputs are crossed.
  187. * Setting ICE1712_STDSP24_BOX_MIDI1 and ICE1712_STDSP24_BOX_MIDI2
  188. * on the same box connects MIDI-In to both 401 uarts; both outputs
  189. * are then active on all boxes.
  190. * The default config here sets up everything on the first box.
  191. * Alan Horstmann 5.2.2008
  192. */
  193. spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
  194. ICE1712_STDSP24_BOX_CHN2 |
  195. ICE1712_STDSP24_BOX_CHN3 |
  196. ICE1712_STDSP24_BOX_CHN4 |
  197. ICE1712_STDSP24_BOX_MIDI1 |
  198. ICE1712_STDSP24_BOX_MIDI2;
  199. if (staudio) {
  200. spec->boxconfig[1] =
  201. spec->boxconfig[2] =
  202. spec->boxconfig[3] = spec->boxconfig[0];
  203. } else {
  204. spec->boxconfig[1] =
  205. spec->boxconfig[2] =
  206. spec->boxconfig[3] = 0;
  207. }
  208. snd_ice1712_stdsp24_darear(ice,
  209. (spec->config & ICE1712_STDSP24_DAREAR) ? 1 : 0);
  210. snd_ice1712_stdsp24_mute(ice,
  211. (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
  212. snd_ice1712_stdsp24_insel(ice,
  213. (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
  214. for (box = 0; box < 4; box++) {
  215. if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
  216. snd_ice1712_stdsp24_midi2(ice, 1);
  217. for (chn = 0; chn < 4; chn++)
  218. snd_ice1712_stdsp24_box_channel(ice, box, chn,
  219. (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
  220. if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1)
  221. snd_ice1712_stdsp24_box_midi(ice, box, 1);
  222. }
  223. return 0;
  224. }
  225. static int snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
  226. {
  227. return hoontech_init(ice, false);
  228. }
  229. static int snd_ice1712_staudio_init(struct snd_ice1712 *ice)
  230. {
  231. return hoontech_init(ice, true);
  232. }
  233. /*
  234. * AK4524 access
  235. */
  236. /* start callback for STDSP24 with modified hardware */
  237. static void stdsp24_ak4524_lock(struct snd_akm4xxx *ak, int chip)
  238. {
  239. struct snd_ice1712 *ice = ak->private_data[0];
  240. unsigned char tmp;
  241. snd_ice1712_save_gpio_status(ice);
  242. tmp = ICE1712_STDSP24_SERIAL_DATA |
  243. ICE1712_STDSP24_SERIAL_CLOCK |
  244. ICE1712_STDSP24_AK4524_CS;
  245. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
  246. ice->gpio.direction | tmp);
  247. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
  248. }
  249. static int snd_ice1712_value_init(struct snd_ice1712 *ice)
  250. {
  251. /* Hoontech STDSP24 with modified hardware */
  252. static const struct snd_akm4xxx akm_stdsp24_mv = {
  253. .num_adcs = 2,
  254. .num_dacs = 2,
  255. .type = SND_AK4524,
  256. .ops = {
  257. .lock = stdsp24_ak4524_lock
  258. }
  259. };
  260. static const struct snd_ak4xxx_private akm_stdsp24_mv_priv = {
  261. .caddr = 2,
  262. .cif = 1, /* CIF high */
  263. .data_mask = ICE1712_STDSP24_SERIAL_DATA,
  264. .clk_mask = ICE1712_STDSP24_SERIAL_CLOCK,
  265. .cs_mask = ICE1712_STDSP24_AK4524_CS,
  266. .cs_addr = ICE1712_STDSP24_AK4524_CS,
  267. .cs_none = 0,
  268. .add_flags = 0,
  269. };
  270. int err;
  271. struct snd_akm4xxx *ak;
  272. /* set the analog DACs */
  273. ice->num_total_dacs = 2;
  274. /* set the analog ADCs */
  275. ice->num_total_adcs = 2;
  276. /* analog section */
  277. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  278. if (! ak)
  279. return -ENOMEM;
  280. ice->akm_codecs = 1;
  281. err = snd_ice1712_akm4xxx_init(ak, &akm_stdsp24_mv, &akm_stdsp24_mv_priv, ice);
  282. if (err < 0)
  283. return err;
  284. /* ak4524 controls */
  285. return snd_ice1712_akm4xxx_build_controls(ice);
  286. }
  287. static int snd_ice1712_ez8_init(struct snd_ice1712 *ice)
  288. {
  289. ice->gpio.write_mask = ice->eeprom.gpiomask;
  290. ice->gpio.direction = ice->eeprom.gpiodir;
  291. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
  292. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
  293. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
  294. return 0;
  295. }
  296. /* entry point */
  297. struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] = {
  298. {
  299. .subvendor = ICE1712_SUBDEVICE_STDSP24,
  300. .name = "Hoontech SoundTrack Audio DSP24",
  301. .model = "dsp24",
  302. .chip_init = snd_ice1712_hoontech_init,
  303. .mpu401_1_name = "MIDI-1 Hoontech/STA DSP24",
  304. .mpu401_2_name = "MIDI-2 Hoontech/STA DSP24",
  305. },
  306. {
  307. .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
  308. .name = "Hoontech SoundTrack Audio DSP24 Value",
  309. .model = "dsp24_value",
  310. .chip_init = snd_ice1712_value_init,
  311. },
  312. {
  313. .subvendor = ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
  314. .name = "Hoontech STA DSP24 Media 7.1",
  315. .model = "dsp24_71",
  316. .chip_init = snd_ice1712_hoontech_init,
  317. },
  318. {
  319. .subvendor = ICE1712_SUBDEVICE_EVENT_EZ8, /* a dummy id */
  320. .name = "Event Electronics EZ8",
  321. .model = "ez8",
  322. .chip_init = snd_ice1712_ez8_init,
  323. },
  324. {
  325. /* STAudio ADCIII has the same SSID as Hoontech StA DSP24,
  326. * thus identified only via the explicit model option
  327. */
  328. .subvendor = ICE1712_SUBDEVICE_STAUDIO_ADCIII, /* a dummy id */
  329. .name = "STAudio ADCIII",
  330. .model = "staudio",
  331. .chip_init = snd_ice1712_staudio_init,
  332. },
  333. { } /* terminator */
  334. };