bebob_maudio.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. /*
  2. * bebob_maudio.c - a part of driver for BeBoB based devices
  3. *
  4. * Copyright (c) 2013-2014 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "./bebob.h"
  9. #include <sound/control.h>
  10. /*
  11. * Just powering on, Firewire 410/Audiophile/1814 and ProjectMix I/O wait to
  12. * download firmware blob. To enable these devices, drivers should upload
  13. * firmware blob and send a command to initialize configuration to factory
  14. * settings when completing uploading. Then these devices generate bus reset
  15. * and are recognized as new devices with the firmware.
  16. *
  17. * But with firmware version 5058 or later, the firmware is stored to flash
  18. * memory in the device and drivers can tell bootloader to load the firmware
  19. * by sending a cue. This cue must be sent one time.
  20. *
  21. * For streaming, both of output and input streams are needed for Firewire 410
  22. * and Ozonic. The single stream is OK for the other devices even if the clock
  23. * source is not SYT-Match (I note no devices use SYT-Match).
  24. *
  25. * Without streaming, the devices except for Firewire Audiophile can mix any
  26. * input and output. For this reason, Audiophile cannot be used as standalone
  27. * mixer.
  28. *
  29. * Firewire 1814 and ProjectMix I/O uses special firmware. It will be freezed
  30. * when receiving any commands which the firmware can't understand. These
  31. * devices utilize completely different system to control. It is some
  32. * write-transaction directly into a certain address. All of addresses for mixer
  33. * functionality is between 0xffc700700000 to 0xffc70070009c.
  34. */
  35. /* Offset from information register */
  36. #define INFO_OFFSET_SW_DATE 0x20
  37. /* Bootloader Protocol Version 1 */
  38. #define MAUDIO_BOOTLOADER_CUE1 0x00000001
  39. /*
  40. * Initializing configuration to factory settings (= 0x1101), (swapped in line),
  41. * Command code is zero (= 0x00),
  42. * the number of operands is zero (= 0x00)(at least significant byte)
  43. */
  44. #define MAUDIO_BOOTLOADER_CUE2 0x01110000
  45. /* padding */
  46. #define MAUDIO_BOOTLOADER_CUE3 0x00000000
  47. #define MAUDIO_SPECIFIC_ADDRESS 0xffc700000000ULL
  48. #define METER_OFFSET 0x00600000
  49. /* some device has sync info after metering data */
  50. #define METER_SIZE_SPECIAL 84 /* with sync info */
  51. #define METER_SIZE_FW410 76 /* with sync info */
  52. #define METER_SIZE_AUDIOPHILE 60 /* with sync info */
  53. #define METER_SIZE_SOLO 52 /* with sync info */
  54. #define METER_SIZE_OZONIC 48
  55. #define METER_SIZE_NRV10 80
  56. /* labels for metering */
  57. #define ANA_IN "Analog In"
  58. #define ANA_OUT "Analog Out"
  59. #define DIG_IN "Digital In"
  60. #define SPDIF_IN "S/PDIF In"
  61. #define ADAT_IN "ADAT In"
  62. #define DIG_OUT "Digital Out"
  63. #define SPDIF_OUT "S/PDIF Out"
  64. #define ADAT_OUT "ADAT Out"
  65. #define STRM_IN "Stream In"
  66. #define AUX_OUT "Aux Out"
  67. #define HP_OUT "HP Out"
  68. /* for NRV */
  69. #define UNKNOWN_METER "Unknown"
  70. struct special_params {
  71. bool is1814;
  72. unsigned int clk_src;
  73. unsigned int dig_in_fmt;
  74. unsigned int dig_out_fmt;
  75. unsigned int clk_lock;
  76. struct snd_ctl_elem_id *ctl_id_sync;
  77. };
  78. /*
  79. * For some M-Audio devices, this module just send cue to load firmware. After
  80. * loading, the device generates bus reset and newly detected.
  81. *
  82. * If we make any transactions to load firmware, the operation may failed.
  83. */
  84. int snd_bebob_maudio_load_firmware(struct fw_unit *unit)
  85. {
  86. struct fw_device *device = fw_parent_device(unit);
  87. int err, rcode;
  88. u64 date;
  89. __be32 cues[3] = {
  90. MAUDIO_BOOTLOADER_CUE1,
  91. MAUDIO_BOOTLOADER_CUE2,
  92. MAUDIO_BOOTLOADER_CUE3
  93. };
  94. /* check date of software used to build */
  95. err = snd_bebob_read_block(unit, INFO_OFFSET_SW_DATE,
  96. &date, sizeof(u64));
  97. if (err < 0)
  98. goto end;
  99. /*
  100. * firmware version 5058 or later has date later than "20070401", but
  101. * 'date' is not null-terminated.
  102. */
  103. if (date < 0x3230303730343031LL) {
  104. dev_err(&unit->device,
  105. "Use firmware version 5058 or later\n");
  106. err = -ENOSYS;
  107. goto end;
  108. }
  109. rcode = fw_run_transaction(device->card, TCODE_WRITE_BLOCK_REQUEST,
  110. device->node_id, device->generation,
  111. device->max_speed, BEBOB_ADDR_REG_REQ,
  112. cues, sizeof(cues));
  113. if (rcode != RCODE_COMPLETE) {
  114. dev_err(&unit->device,
  115. "Failed to send a cue to load firmware\n");
  116. err = -EIO;
  117. }
  118. end:
  119. return err;
  120. }
  121. static inline int
  122. get_meter(struct snd_bebob *bebob, void *buf, unsigned int size)
  123. {
  124. return snd_fw_transaction(bebob->unit, TCODE_READ_BLOCK_REQUEST,
  125. MAUDIO_SPECIFIC_ADDRESS + METER_OFFSET,
  126. buf, size, 0);
  127. }
  128. static int
  129. check_clk_sync(struct snd_bebob *bebob, unsigned int size, bool *sync)
  130. {
  131. int err;
  132. u8 *buf;
  133. buf = kmalloc(size, GFP_KERNEL);
  134. if (buf == NULL)
  135. return -ENOMEM;
  136. err = get_meter(bebob, buf, size);
  137. if (err < 0)
  138. goto end;
  139. /* if synced, this value is the same as SFC of FDF in CIP header */
  140. *sync = (buf[size - 2] != 0xff);
  141. end:
  142. kfree(buf);
  143. return err;
  144. }
  145. /*
  146. * dig_fmt: 0x00:S/PDIF, 0x01:ADAT
  147. * clk_lock: 0x00:unlock, 0x01:lock
  148. */
  149. static int
  150. avc_maudio_set_special_clk(struct snd_bebob *bebob, unsigned int clk_src,
  151. unsigned int dig_in_fmt, unsigned int dig_out_fmt,
  152. unsigned int clk_lock)
  153. {
  154. struct special_params *params = bebob->maudio_special_quirk;
  155. int err;
  156. u8 *buf;
  157. if (amdtp_stream_running(&bebob->rx_stream) ||
  158. amdtp_stream_running(&bebob->tx_stream))
  159. return -EBUSY;
  160. buf = kmalloc(12, GFP_KERNEL);
  161. if (buf == NULL)
  162. return -ENOMEM;
  163. buf[0] = 0x00; /* CONTROL */
  164. buf[1] = 0xff; /* UNIT */
  165. buf[2] = 0x00; /* vendor dependent */
  166. buf[3] = 0x04; /* company ID high */
  167. buf[4] = 0x00; /* company ID middle */
  168. buf[5] = 0x04; /* company ID low */
  169. buf[6] = 0xff & clk_src; /* clock source */
  170. buf[7] = 0xff & dig_in_fmt; /* input digital format */
  171. buf[8] = 0xff & dig_out_fmt; /* output digital format */
  172. buf[9] = 0xff & clk_lock; /* lock these settings */
  173. buf[10] = 0x00; /* padding */
  174. buf[11] = 0x00; /* padding */
  175. err = fcp_avc_transaction(bebob->unit, buf, 12, buf, 12,
  176. BIT(1) | BIT(2) | BIT(3) | BIT(4) |
  177. BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  178. BIT(9));
  179. if ((err > 0) && (err < 10))
  180. err = -EIO;
  181. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  182. err = -ENOSYS;
  183. else if (buf[0] == 0x0a) /* REJECTED */
  184. err = -EINVAL;
  185. if (err < 0)
  186. goto end;
  187. params->clk_src = buf[6];
  188. params->dig_in_fmt = buf[7];
  189. params->dig_out_fmt = buf[8];
  190. params->clk_lock = buf[9];
  191. if (params->ctl_id_sync)
  192. snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,
  193. params->ctl_id_sync);
  194. err = 0;
  195. end:
  196. kfree(buf);
  197. return err;
  198. }
  199. static void
  200. special_stream_formation_set(struct snd_bebob *bebob)
  201. {
  202. static const unsigned int ch_table[2][2][3] = {
  203. /* AMDTP_OUT_STREAM */
  204. { { 6, 6, 4 }, /* SPDIF */
  205. { 12, 8, 4 } }, /* ADAT */
  206. /* AMDTP_IN_STREAM */
  207. { { 10, 10, 2 }, /* SPDIF */
  208. { 16, 12, 2 } } /* ADAT */
  209. };
  210. struct special_params *params = bebob->maudio_special_quirk;
  211. unsigned int i, max;
  212. max = SND_BEBOB_STRM_FMT_ENTRIES - 1;
  213. if (!params->is1814)
  214. max -= 2;
  215. for (i = 0; i < max; i++) {
  216. bebob->tx_stream_formations[i + 1].pcm =
  217. ch_table[AMDTP_IN_STREAM][params->dig_in_fmt][i / 2];
  218. bebob->tx_stream_formations[i + 1].midi = 1;
  219. bebob->rx_stream_formations[i + 1].pcm =
  220. ch_table[AMDTP_OUT_STREAM][params->dig_out_fmt][i / 2];
  221. bebob->rx_stream_formations[i + 1].midi = 1;
  222. }
  223. }
  224. static int add_special_controls(struct snd_bebob *bebob);
  225. int
  226. snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
  227. {
  228. struct special_params *params;
  229. int err;
  230. params = kzalloc(sizeof(struct special_params), GFP_KERNEL);
  231. if (params == NULL)
  232. return -ENOMEM;
  233. mutex_lock(&bebob->mutex);
  234. bebob->maudio_special_quirk = (void *)params;
  235. params->is1814 = is1814;
  236. /* initialize these parameters because driver is not allowed to ask */
  237. bebob->rx_stream.context = ERR_PTR(-1);
  238. bebob->tx_stream.context = ERR_PTR(-1);
  239. err = avc_maudio_set_special_clk(bebob, 0x03, 0x00, 0x00, 0x00);
  240. if (err < 0) {
  241. dev_err(&bebob->unit->device,
  242. "fail to initialize clock params: %d\n", err);
  243. goto end;
  244. }
  245. err = add_special_controls(bebob);
  246. if (err < 0)
  247. goto end;
  248. special_stream_formation_set(bebob);
  249. if (params->is1814) {
  250. bebob->midi_input_ports = 1;
  251. bebob->midi_output_ports = 1;
  252. } else {
  253. bebob->midi_input_ports = 2;
  254. bebob->midi_output_ports = 2;
  255. }
  256. end:
  257. if (err < 0) {
  258. kfree(params);
  259. bebob->maudio_special_quirk = NULL;
  260. }
  261. mutex_unlock(&bebob->mutex);
  262. return err;
  263. }
  264. /* Input plug shows actual rate. Output plug is needless for this purpose. */
  265. static int special_get_rate(struct snd_bebob *bebob, unsigned int *rate)
  266. {
  267. int err, trials;
  268. trials = 0;
  269. do {
  270. err = avc_general_get_sig_fmt(bebob->unit, rate,
  271. AVC_GENERAL_PLUG_DIR_IN, 0);
  272. } while (err == -EAGAIN && ++trials < 3);
  273. return err;
  274. }
  275. static int special_set_rate(struct snd_bebob *bebob, unsigned int rate)
  276. {
  277. struct special_params *params = bebob->maudio_special_quirk;
  278. int err;
  279. err = avc_general_set_sig_fmt(bebob->unit, rate,
  280. AVC_GENERAL_PLUG_DIR_OUT, 0);
  281. if (err < 0)
  282. goto end;
  283. /*
  284. * Just after changing sampling rate for output, a followed command
  285. * for input is easy to fail. This is a workaround fot this issue.
  286. */
  287. msleep(100);
  288. err = avc_general_set_sig_fmt(bebob->unit, rate,
  289. AVC_GENERAL_PLUG_DIR_IN, 0);
  290. if (err < 0)
  291. goto end;
  292. if (params->ctl_id_sync)
  293. snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,
  294. params->ctl_id_sync);
  295. end:
  296. return err;
  297. }
  298. /* Clock source control for special firmware */
  299. static char *const special_clk_labels[] = {
  300. SND_BEBOB_CLOCK_INTERNAL " with Digital Mute", "Digital",
  301. "Word Clock", SND_BEBOB_CLOCK_INTERNAL};
  302. static int special_clk_get(struct snd_bebob *bebob, unsigned int *id)
  303. {
  304. struct special_params *params = bebob->maudio_special_quirk;
  305. *id = params->clk_src;
  306. return 0;
  307. }
  308. static int special_clk_ctl_info(struct snd_kcontrol *kctl,
  309. struct snd_ctl_elem_info *einf)
  310. {
  311. einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  312. einf->count = 1;
  313. einf->value.enumerated.items = ARRAY_SIZE(special_clk_labels);
  314. if (einf->value.enumerated.item >= einf->value.enumerated.items)
  315. einf->value.enumerated.item = einf->value.enumerated.items - 1;
  316. strcpy(einf->value.enumerated.name,
  317. special_clk_labels[einf->value.enumerated.item]);
  318. return 0;
  319. }
  320. static int special_clk_ctl_get(struct snd_kcontrol *kctl,
  321. struct snd_ctl_elem_value *uval)
  322. {
  323. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  324. struct special_params *params = bebob->maudio_special_quirk;
  325. uval->value.enumerated.item[0] = params->clk_src;
  326. return 0;
  327. }
  328. static int special_clk_ctl_put(struct snd_kcontrol *kctl,
  329. struct snd_ctl_elem_value *uval)
  330. {
  331. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  332. struct special_params *params = bebob->maudio_special_quirk;
  333. int err, id;
  334. id = uval->value.enumerated.item[0];
  335. if (id >= ARRAY_SIZE(special_clk_labels))
  336. return -EINVAL;
  337. mutex_lock(&bebob->mutex);
  338. err = avc_maudio_set_special_clk(bebob, id,
  339. params->dig_in_fmt,
  340. params->dig_out_fmt,
  341. params->clk_lock);
  342. mutex_unlock(&bebob->mutex);
  343. if (err >= 0)
  344. err = 1;
  345. return err;
  346. }
  347. static struct snd_kcontrol_new special_clk_ctl = {
  348. .name = "Clock Source",
  349. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  350. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  351. .info = special_clk_ctl_info,
  352. .get = special_clk_ctl_get,
  353. .put = special_clk_ctl_put
  354. };
  355. /* Clock synchronization control for special firmware */
  356. static int special_sync_ctl_info(struct snd_kcontrol *kctl,
  357. struct snd_ctl_elem_info *einf)
  358. {
  359. einf->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  360. einf->count = 1;
  361. einf->value.integer.min = 0;
  362. einf->value.integer.max = 1;
  363. return 0;
  364. }
  365. static int special_sync_ctl_get(struct snd_kcontrol *kctl,
  366. struct snd_ctl_elem_value *uval)
  367. {
  368. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  369. int err;
  370. bool synced = 0;
  371. err = check_clk_sync(bebob, METER_SIZE_SPECIAL, &synced);
  372. if (err >= 0)
  373. uval->value.integer.value[0] = synced;
  374. return 0;
  375. }
  376. static struct snd_kcontrol_new special_sync_ctl = {
  377. .name = "Sync Status",
  378. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  379. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  380. .info = special_sync_ctl_info,
  381. .get = special_sync_ctl_get,
  382. };
  383. /* Digital input interface control for special firmware */
  384. static char *const special_dig_in_iface_labels[] = {
  385. "S/PDIF Optical", "S/PDIF Coaxial", "ADAT Optical"
  386. };
  387. static int special_dig_in_iface_ctl_info(struct snd_kcontrol *kctl,
  388. struct snd_ctl_elem_info *einf)
  389. {
  390. einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  391. einf->count = 1;
  392. einf->value.enumerated.items = ARRAY_SIZE(special_dig_in_iface_labels);
  393. if (einf->value.enumerated.item >= einf->value.enumerated.items)
  394. einf->value.enumerated.item = einf->value.enumerated.items - 1;
  395. strcpy(einf->value.enumerated.name,
  396. special_dig_in_iface_labels[einf->value.enumerated.item]);
  397. return 0;
  398. }
  399. static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
  400. struct snd_ctl_elem_value *uval)
  401. {
  402. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  403. struct special_params *params = bebob->maudio_special_quirk;
  404. unsigned int dig_in_iface;
  405. int err, val;
  406. mutex_lock(&bebob->mutex);
  407. err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,
  408. &dig_in_iface);
  409. if (err < 0) {
  410. dev_err(&bebob->unit->device,
  411. "fail to get digital input interface: %d\n", err);
  412. goto end;
  413. }
  414. /* encoded id for user value */
  415. val = (params->dig_in_fmt << 1) | (dig_in_iface & 0x01);
  416. /* for ADAT Optical */
  417. if (val > 2)
  418. val = 2;
  419. uval->value.enumerated.item[0] = val;
  420. end:
  421. mutex_unlock(&bebob->mutex);
  422. return err;
  423. }
  424. static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
  425. struct snd_ctl_elem_value *uval)
  426. {
  427. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  428. struct special_params *params = bebob->maudio_special_quirk;
  429. unsigned int id, dig_in_fmt, dig_in_iface;
  430. int err;
  431. id = uval->value.enumerated.item[0];
  432. if (id >= ARRAY_SIZE(special_dig_in_iface_labels))
  433. return -EINVAL;
  434. /* decode user value */
  435. dig_in_fmt = (id >> 1) & 0x01;
  436. dig_in_iface = id & 0x01;
  437. mutex_lock(&bebob->mutex);
  438. err = avc_maudio_set_special_clk(bebob,
  439. params->clk_src,
  440. dig_in_fmt,
  441. params->dig_out_fmt,
  442. params->clk_lock);
  443. if (err < 0)
  444. goto end;
  445. /* For ADAT, optical interface is only available. */
  446. if (params->dig_in_fmt > 0) {
  447. err = 1;
  448. goto end;
  449. }
  450. /* For S/PDIF, optical/coaxial interfaces are selectable. */
  451. err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);
  452. if (err < 0)
  453. dev_err(&bebob->unit->device,
  454. "fail to set digital input interface: %d\n", err);
  455. err = 1;
  456. end:
  457. special_stream_formation_set(bebob);
  458. mutex_unlock(&bebob->mutex);
  459. return err;
  460. }
  461. static struct snd_kcontrol_new special_dig_in_iface_ctl = {
  462. .name = "Digital Input Interface",
  463. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  464. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  465. .info = special_dig_in_iface_ctl_info,
  466. .get = special_dig_in_iface_ctl_get,
  467. .put = special_dig_in_iface_ctl_set
  468. };
  469. /* Digital output interface control for special firmware */
  470. static char *const special_dig_out_iface_labels[] = {
  471. "S/PDIF Optical and Coaxial", "ADAT Optical"
  472. };
  473. static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl,
  474. struct snd_ctl_elem_info *einf)
  475. {
  476. einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  477. einf->count = 1;
  478. einf->value.enumerated.items = ARRAY_SIZE(special_dig_out_iface_labels);
  479. if (einf->value.enumerated.item >= einf->value.enumerated.items)
  480. einf->value.enumerated.item = einf->value.enumerated.items - 1;
  481. strcpy(einf->value.enumerated.name,
  482. special_dig_out_iface_labels[einf->value.enumerated.item]);
  483. return 0;
  484. }
  485. static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
  486. struct snd_ctl_elem_value *uval)
  487. {
  488. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  489. struct special_params *params = bebob->maudio_special_quirk;
  490. mutex_lock(&bebob->mutex);
  491. uval->value.enumerated.item[0] = params->dig_out_fmt;
  492. mutex_unlock(&bebob->mutex);
  493. return 0;
  494. }
  495. static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
  496. struct snd_ctl_elem_value *uval)
  497. {
  498. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  499. struct special_params *params = bebob->maudio_special_quirk;
  500. unsigned int id;
  501. int err;
  502. id = uval->value.enumerated.item[0];
  503. if (id >= ARRAY_SIZE(special_dig_out_iface_labels))
  504. return -EINVAL;
  505. mutex_lock(&bebob->mutex);
  506. err = avc_maudio_set_special_clk(bebob,
  507. params->clk_src,
  508. params->dig_in_fmt,
  509. id, params->clk_lock);
  510. if (err >= 0) {
  511. special_stream_formation_set(bebob);
  512. err = 1;
  513. }
  514. mutex_unlock(&bebob->mutex);
  515. return err;
  516. }
  517. static struct snd_kcontrol_new special_dig_out_iface_ctl = {
  518. .name = "Digital Output Interface",
  519. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  520. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  521. .info = special_dig_out_iface_ctl_info,
  522. .get = special_dig_out_iface_ctl_get,
  523. .put = special_dig_out_iface_ctl_set
  524. };
  525. static int add_special_controls(struct snd_bebob *bebob)
  526. {
  527. struct snd_kcontrol *kctl;
  528. struct special_params *params = bebob->maudio_special_quirk;
  529. int err;
  530. kctl = snd_ctl_new1(&special_clk_ctl, bebob);
  531. err = snd_ctl_add(bebob->card, kctl);
  532. if (err < 0)
  533. goto end;
  534. kctl = snd_ctl_new1(&special_sync_ctl, bebob);
  535. err = snd_ctl_add(bebob->card, kctl);
  536. if (err < 0)
  537. goto end;
  538. params->ctl_id_sync = &kctl->id;
  539. kctl = snd_ctl_new1(&special_dig_in_iface_ctl, bebob);
  540. err = snd_ctl_add(bebob->card, kctl);
  541. if (err < 0)
  542. goto end;
  543. kctl = snd_ctl_new1(&special_dig_out_iface_ctl, bebob);
  544. err = snd_ctl_add(bebob->card, kctl);
  545. end:
  546. return err;
  547. }
  548. /* Hardware metering for special firmware */
  549. static char *const special_meter_labels[] = {
  550. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  551. SPDIF_IN,
  552. ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN,
  553. ANA_OUT, ANA_OUT,
  554. SPDIF_OUT,
  555. ADAT_OUT, ADAT_OUT, ADAT_OUT, ADAT_OUT,
  556. HP_OUT, HP_OUT,
  557. AUX_OUT
  558. };
  559. static int
  560. special_meter_get(struct snd_bebob *bebob, u32 *target, unsigned int size)
  561. {
  562. u16 *buf;
  563. unsigned int i, c, channels;
  564. int err;
  565. channels = ARRAY_SIZE(special_meter_labels) * 2;
  566. if (size < channels * sizeof(u32))
  567. return -EINVAL;
  568. /* omit last 4 bytes because it's clock info. */
  569. buf = kmalloc(METER_SIZE_SPECIAL - 4, GFP_KERNEL);
  570. if (buf == NULL)
  571. return -ENOMEM;
  572. err = get_meter(bebob, (void *)buf, METER_SIZE_SPECIAL - 4);
  573. if (err < 0)
  574. goto end;
  575. /* Its format is u16 and some channels are unknown. */
  576. i = 0;
  577. for (c = 2; c < channels + 2; c++)
  578. target[i++] = be16_to_cpu(buf[c]) << 16;
  579. end:
  580. kfree(buf);
  581. return err;
  582. }
  583. /* last 4 bytes are omitted because it's clock info. */
  584. static char *const fw410_meter_labels[] = {
  585. ANA_IN, DIG_IN,
  586. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT,
  587. HP_OUT
  588. };
  589. static char *const audiophile_meter_labels[] = {
  590. ANA_IN, DIG_IN,
  591. ANA_OUT, ANA_OUT, DIG_OUT,
  592. HP_OUT, AUX_OUT,
  593. };
  594. static char *const solo_meter_labels[] = {
  595. ANA_IN, DIG_IN,
  596. STRM_IN, STRM_IN,
  597. ANA_OUT, DIG_OUT
  598. };
  599. /* no clock info */
  600. static char *const ozonic_meter_labels[] = {
  601. ANA_IN, ANA_IN,
  602. STRM_IN, STRM_IN,
  603. ANA_OUT, ANA_OUT
  604. };
  605. /* TODO: need testers. these positions are based on authour's assumption */
  606. static char *const nrv10_meter_labels[] = {
  607. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  608. DIG_IN,
  609. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
  610. DIG_IN
  611. };
  612. static int
  613. normal_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)
  614. {
  615. struct snd_bebob_meter_spec *spec = bebob->spec->meter;
  616. unsigned int c, channels;
  617. int err;
  618. channels = spec->num * 2;
  619. if (size < channels * sizeof(u32))
  620. return -EINVAL;
  621. err = get_meter(bebob, (void *)buf, size);
  622. if (err < 0)
  623. goto end;
  624. for (c = 0; c < channels; c++)
  625. be32_to_cpus(&buf[c]);
  626. /* swap stream channels because inverted */
  627. if (spec->labels == solo_meter_labels) {
  628. swap(buf[4], buf[6]);
  629. swap(buf[5], buf[7]);
  630. }
  631. end:
  632. return err;
  633. }
  634. /* for special customized devices */
  635. static struct snd_bebob_rate_spec special_rate_spec = {
  636. .get = &special_get_rate,
  637. .set = &special_set_rate,
  638. };
  639. static struct snd_bebob_clock_spec special_clk_spec = {
  640. .num = ARRAY_SIZE(special_clk_labels),
  641. .labels = special_clk_labels,
  642. .get = &special_clk_get,
  643. };
  644. static struct snd_bebob_meter_spec special_meter_spec = {
  645. .num = ARRAY_SIZE(special_meter_labels),
  646. .labels = special_meter_labels,
  647. .get = &special_meter_get
  648. };
  649. struct snd_bebob_spec maudio_special_spec = {
  650. .clock = &special_clk_spec,
  651. .rate = &special_rate_spec,
  652. .meter = &special_meter_spec
  653. };
  654. /* Firewire 410 specification */
  655. static struct snd_bebob_rate_spec usual_rate_spec = {
  656. .get = &snd_bebob_stream_get_rate,
  657. .set = &snd_bebob_stream_set_rate,
  658. };
  659. static struct snd_bebob_meter_spec fw410_meter_spec = {
  660. .num = ARRAY_SIZE(fw410_meter_labels),
  661. .labels = fw410_meter_labels,
  662. .get = &normal_meter_get
  663. };
  664. struct snd_bebob_spec maudio_fw410_spec = {
  665. .clock = NULL,
  666. .rate = &usual_rate_spec,
  667. .meter = &fw410_meter_spec
  668. };
  669. /* Firewire Audiophile specification */
  670. static struct snd_bebob_meter_spec audiophile_meter_spec = {
  671. .num = ARRAY_SIZE(audiophile_meter_labels),
  672. .labels = audiophile_meter_labels,
  673. .get = &normal_meter_get
  674. };
  675. struct snd_bebob_spec maudio_audiophile_spec = {
  676. .clock = NULL,
  677. .rate = &usual_rate_spec,
  678. .meter = &audiophile_meter_spec
  679. };
  680. /* Firewire Solo specification */
  681. static struct snd_bebob_meter_spec solo_meter_spec = {
  682. .num = ARRAY_SIZE(solo_meter_labels),
  683. .labels = solo_meter_labels,
  684. .get = &normal_meter_get
  685. };
  686. struct snd_bebob_spec maudio_solo_spec = {
  687. .clock = NULL,
  688. .rate = &usual_rate_spec,
  689. .meter = &solo_meter_spec
  690. };
  691. /* Ozonic specification */
  692. static struct snd_bebob_meter_spec ozonic_meter_spec = {
  693. .num = ARRAY_SIZE(ozonic_meter_labels),
  694. .labels = ozonic_meter_labels,
  695. .get = &normal_meter_get
  696. };
  697. struct snd_bebob_spec maudio_ozonic_spec = {
  698. .clock = NULL,
  699. .rate = &usual_rate_spec,
  700. .meter = &ozonic_meter_spec
  701. };
  702. /* NRV10 specification */
  703. static struct snd_bebob_meter_spec nrv10_meter_spec = {
  704. .num = ARRAY_SIZE(nrv10_meter_labels),
  705. .labels = nrv10_meter_labels,
  706. .get = &normal_meter_get
  707. };
  708. struct snd_bebob_spec maudio_nrv10_spec = {
  709. .clock = NULL,
  710. .rate = &usual_rate_spec,
  711. .meter = &nrv10_meter_spec
  712. };