hoontech.c 11 KB

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