bebob_maudio.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. __le32 cues[3] = {
  90. cpu_to_le32(MAUDIO_BOOTLOADER_CUE1),
  91. cpu_to_le32(MAUDIO_BOOTLOADER_CUE2),
  92. cpu_to_le32(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 const 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. return snd_ctl_enum_info(einf, 1, ARRAY_SIZE(special_clk_labels),
  312. special_clk_labels);
  313. }
  314. static int special_clk_ctl_get(struct snd_kcontrol *kctl,
  315. struct snd_ctl_elem_value *uval)
  316. {
  317. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  318. struct special_params *params = bebob->maudio_special_quirk;
  319. uval->value.enumerated.item[0] = params->clk_src;
  320. return 0;
  321. }
  322. static int special_clk_ctl_put(struct snd_kcontrol *kctl,
  323. struct snd_ctl_elem_value *uval)
  324. {
  325. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  326. struct special_params *params = bebob->maudio_special_quirk;
  327. int err, id;
  328. id = uval->value.enumerated.item[0];
  329. if (id >= ARRAY_SIZE(special_clk_labels))
  330. return -EINVAL;
  331. mutex_lock(&bebob->mutex);
  332. err = avc_maudio_set_special_clk(bebob, id,
  333. params->dig_in_fmt,
  334. params->dig_out_fmt,
  335. params->clk_lock);
  336. mutex_unlock(&bebob->mutex);
  337. if (err >= 0)
  338. err = 1;
  339. return err;
  340. }
  341. static struct snd_kcontrol_new special_clk_ctl = {
  342. .name = "Clock Source",
  343. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  344. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  345. .info = special_clk_ctl_info,
  346. .get = special_clk_ctl_get,
  347. .put = special_clk_ctl_put
  348. };
  349. /* Clock synchronization control for special firmware */
  350. static int special_sync_ctl_info(struct snd_kcontrol *kctl,
  351. struct snd_ctl_elem_info *einf)
  352. {
  353. einf->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  354. einf->count = 1;
  355. einf->value.integer.min = 0;
  356. einf->value.integer.max = 1;
  357. return 0;
  358. }
  359. static int special_sync_ctl_get(struct snd_kcontrol *kctl,
  360. struct snd_ctl_elem_value *uval)
  361. {
  362. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  363. int err;
  364. bool synced = 0;
  365. err = check_clk_sync(bebob, METER_SIZE_SPECIAL, &synced);
  366. if (err >= 0)
  367. uval->value.integer.value[0] = synced;
  368. return 0;
  369. }
  370. static struct snd_kcontrol_new special_sync_ctl = {
  371. .name = "Sync Status",
  372. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  373. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  374. .info = special_sync_ctl_info,
  375. .get = special_sync_ctl_get,
  376. };
  377. /* Digital input interface control for special firmware */
  378. static const char *const special_dig_in_iface_labels[] = {
  379. "S/PDIF Optical", "S/PDIF Coaxial", "ADAT Optical"
  380. };
  381. static int special_dig_in_iface_ctl_info(struct snd_kcontrol *kctl,
  382. struct snd_ctl_elem_info *einf)
  383. {
  384. return snd_ctl_enum_info(einf, 1,
  385. ARRAY_SIZE(special_dig_in_iface_labels),
  386. special_dig_in_iface_labels);
  387. }
  388. static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
  389. struct snd_ctl_elem_value *uval)
  390. {
  391. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  392. struct special_params *params = bebob->maudio_special_quirk;
  393. unsigned int dig_in_iface;
  394. int err, val;
  395. mutex_lock(&bebob->mutex);
  396. err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,
  397. &dig_in_iface);
  398. if (err < 0) {
  399. dev_err(&bebob->unit->device,
  400. "fail to get digital input interface: %d\n", err);
  401. goto end;
  402. }
  403. /* encoded id for user value */
  404. val = (params->dig_in_fmt << 1) | (dig_in_iface & 0x01);
  405. /* for ADAT Optical */
  406. if (val > 2)
  407. val = 2;
  408. uval->value.enumerated.item[0] = val;
  409. end:
  410. mutex_unlock(&bebob->mutex);
  411. return err;
  412. }
  413. static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
  414. struct snd_ctl_elem_value *uval)
  415. {
  416. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  417. struct special_params *params = bebob->maudio_special_quirk;
  418. unsigned int id, dig_in_fmt, dig_in_iface;
  419. int err;
  420. id = uval->value.enumerated.item[0];
  421. if (id >= ARRAY_SIZE(special_dig_in_iface_labels))
  422. return -EINVAL;
  423. /* decode user value */
  424. dig_in_fmt = (id >> 1) & 0x01;
  425. dig_in_iface = id & 0x01;
  426. mutex_lock(&bebob->mutex);
  427. err = avc_maudio_set_special_clk(bebob,
  428. params->clk_src,
  429. dig_in_fmt,
  430. params->dig_out_fmt,
  431. params->clk_lock);
  432. if (err < 0)
  433. goto end;
  434. /* For ADAT, optical interface is only available. */
  435. if (params->dig_in_fmt > 0) {
  436. err = 1;
  437. goto end;
  438. }
  439. /* For S/PDIF, optical/coaxial interfaces are selectable. */
  440. err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);
  441. if (err < 0)
  442. dev_err(&bebob->unit->device,
  443. "fail to set digital input interface: %d\n", err);
  444. err = 1;
  445. end:
  446. special_stream_formation_set(bebob);
  447. mutex_unlock(&bebob->mutex);
  448. return err;
  449. }
  450. static struct snd_kcontrol_new special_dig_in_iface_ctl = {
  451. .name = "Digital Input Interface",
  452. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  453. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  454. .info = special_dig_in_iface_ctl_info,
  455. .get = special_dig_in_iface_ctl_get,
  456. .put = special_dig_in_iface_ctl_set
  457. };
  458. /* Digital output interface control for special firmware */
  459. static const char *const special_dig_out_iface_labels[] = {
  460. "S/PDIF Optical and Coaxial", "ADAT Optical"
  461. };
  462. static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl,
  463. struct snd_ctl_elem_info *einf)
  464. {
  465. return snd_ctl_enum_info(einf, 1,
  466. ARRAY_SIZE(special_dig_out_iface_labels),
  467. special_dig_out_iface_labels);
  468. }
  469. static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
  470. struct snd_ctl_elem_value *uval)
  471. {
  472. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  473. struct special_params *params = bebob->maudio_special_quirk;
  474. mutex_lock(&bebob->mutex);
  475. uval->value.enumerated.item[0] = params->dig_out_fmt;
  476. mutex_unlock(&bebob->mutex);
  477. return 0;
  478. }
  479. static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
  480. struct snd_ctl_elem_value *uval)
  481. {
  482. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  483. struct special_params *params = bebob->maudio_special_quirk;
  484. unsigned int id;
  485. int err;
  486. id = uval->value.enumerated.item[0];
  487. if (id >= ARRAY_SIZE(special_dig_out_iface_labels))
  488. return -EINVAL;
  489. mutex_lock(&bebob->mutex);
  490. err = avc_maudio_set_special_clk(bebob,
  491. params->clk_src,
  492. params->dig_in_fmt,
  493. id, params->clk_lock);
  494. if (err >= 0) {
  495. special_stream_formation_set(bebob);
  496. err = 1;
  497. }
  498. mutex_unlock(&bebob->mutex);
  499. return err;
  500. }
  501. static struct snd_kcontrol_new special_dig_out_iface_ctl = {
  502. .name = "Digital Output Interface",
  503. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  504. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  505. .info = special_dig_out_iface_ctl_info,
  506. .get = special_dig_out_iface_ctl_get,
  507. .put = special_dig_out_iface_ctl_set
  508. };
  509. static int add_special_controls(struct snd_bebob *bebob)
  510. {
  511. struct snd_kcontrol *kctl;
  512. struct special_params *params = bebob->maudio_special_quirk;
  513. int err;
  514. kctl = snd_ctl_new1(&special_clk_ctl, bebob);
  515. err = snd_ctl_add(bebob->card, kctl);
  516. if (err < 0)
  517. goto end;
  518. kctl = snd_ctl_new1(&special_sync_ctl, bebob);
  519. err = snd_ctl_add(bebob->card, kctl);
  520. if (err < 0)
  521. goto end;
  522. params->ctl_id_sync = &kctl->id;
  523. kctl = snd_ctl_new1(&special_dig_in_iface_ctl, bebob);
  524. err = snd_ctl_add(bebob->card, kctl);
  525. if (err < 0)
  526. goto end;
  527. kctl = snd_ctl_new1(&special_dig_out_iface_ctl, bebob);
  528. err = snd_ctl_add(bebob->card, kctl);
  529. end:
  530. return err;
  531. }
  532. /* Hardware metering for special firmware */
  533. static const char *const special_meter_labels[] = {
  534. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  535. SPDIF_IN,
  536. ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN,
  537. ANA_OUT, ANA_OUT,
  538. SPDIF_OUT,
  539. ADAT_OUT, ADAT_OUT, ADAT_OUT, ADAT_OUT,
  540. HP_OUT, HP_OUT,
  541. AUX_OUT
  542. };
  543. static int
  544. special_meter_get(struct snd_bebob *bebob, u32 *target, unsigned int size)
  545. {
  546. u16 *buf;
  547. unsigned int i, c, channels;
  548. int err;
  549. channels = ARRAY_SIZE(special_meter_labels) * 2;
  550. if (size < channels * sizeof(u32))
  551. return -EINVAL;
  552. /* omit last 4 bytes because it's clock info. */
  553. buf = kmalloc(METER_SIZE_SPECIAL - 4, GFP_KERNEL);
  554. if (buf == NULL)
  555. return -ENOMEM;
  556. err = get_meter(bebob, (void *)buf, METER_SIZE_SPECIAL - 4);
  557. if (err < 0)
  558. goto end;
  559. /* Its format is u16 and some channels are unknown. */
  560. i = 0;
  561. for (c = 2; c < channels + 2; c++)
  562. target[i++] = be16_to_cpu(buf[c]) << 16;
  563. end:
  564. kfree(buf);
  565. return err;
  566. }
  567. /* last 4 bytes are omitted because it's clock info. */
  568. static const char *const fw410_meter_labels[] = {
  569. ANA_IN, DIG_IN,
  570. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT,
  571. HP_OUT
  572. };
  573. static const char *const audiophile_meter_labels[] = {
  574. ANA_IN, DIG_IN,
  575. ANA_OUT, ANA_OUT, DIG_OUT,
  576. HP_OUT, AUX_OUT,
  577. };
  578. static const char *const solo_meter_labels[] = {
  579. ANA_IN, DIG_IN,
  580. STRM_IN, STRM_IN,
  581. ANA_OUT, DIG_OUT
  582. };
  583. /* no clock info */
  584. static const char *const ozonic_meter_labels[] = {
  585. ANA_IN, ANA_IN,
  586. STRM_IN, STRM_IN,
  587. ANA_OUT, ANA_OUT
  588. };
  589. /* TODO: need testers. these positions are based on authour's assumption */
  590. static const char *const nrv10_meter_labels[] = {
  591. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  592. DIG_IN,
  593. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
  594. DIG_IN
  595. };
  596. static int
  597. normal_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)
  598. {
  599. struct snd_bebob_meter_spec *spec = bebob->spec->meter;
  600. unsigned int c, channels;
  601. int err;
  602. channels = spec->num * 2;
  603. if (size < channels * sizeof(u32))
  604. return -EINVAL;
  605. err = get_meter(bebob, (void *)buf, size);
  606. if (err < 0)
  607. goto end;
  608. for (c = 0; c < channels; c++)
  609. be32_to_cpus(&buf[c]);
  610. /* swap stream channels because inverted */
  611. if (spec->labels == solo_meter_labels) {
  612. swap(buf[4], buf[6]);
  613. swap(buf[5], buf[7]);
  614. }
  615. end:
  616. return err;
  617. }
  618. /* for special customized devices */
  619. static struct snd_bebob_rate_spec special_rate_spec = {
  620. .get = &special_get_rate,
  621. .set = &special_set_rate,
  622. };
  623. static struct snd_bebob_clock_spec special_clk_spec = {
  624. .num = ARRAY_SIZE(special_clk_labels),
  625. .labels = special_clk_labels,
  626. .get = &special_clk_get,
  627. };
  628. static struct snd_bebob_meter_spec special_meter_spec = {
  629. .num = ARRAY_SIZE(special_meter_labels),
  630. .labels = special_meter_labels,
  631. .get = &special_meter_get
  632. };
  633. struct snd_bebob_spec maudio_special_spec = {
  634. .clock = &special_clk_spec,
  635. .rate = &special_rate_spec,
  636. .meter = &special_meter_spec
  637. };
  638. /* Firewire 410 specification */
  639. static struct snd_bebob_rate_spec usual_rate_spec = {
  640. .get = &snd_bebob_stream_get_rate,
  641. .set = &snd_bebob_stream_set_rate,
  642. };
  643. static struct snd_bebob_meter_spec fw410_meter_spec = {
  644. .num = ARRAY_SIZE(fw410_meter_labels),
  645. .labels = fw410_meter_labels,
  646. .get = &normal_meter_get
  647. };
  648. struct snd_bebob_spec maudio_fw410_spec = {
  649. .clock = NULL,
  650. .rate = &usual_rate_spec,
  651. .meter = &fw410_meter_spec
  652. };
  653. /* Firewire Audiophile specification */
  654. static struct snd_bebob_meter_spec audiophile_meter_spec = {
  655. .num = ARRAY_SIZE(audiophile_meter_labels),
  656. .labels = audiophile_meter_labels,
  657. .get = &normal_meter_get
  658. };
  659. struct snd_bebob_spec maudio_audiophile_spec = {
  660. .clock = NULL,
  661. .rate = &usual_rate_spec,
  662. .meter = &audiophile_meter_spec
  663. };
  664. /* Firewire Solo specification */
  665. static struct snd_bebob_meter_spec solo_meter_spec = {
  666. .num = ARRAY_SIZE(solo_meter_labels),
  667. .labels = solo_meter_labels,
  668. .get = &normal_meter_get
  669. };
  670. struct snd_bebob_spec maudio_solo_spec = {
  671. .clock = NULL,
  672. .rate = &usual_rate_spec,
  673. .meter = &solo_meter_spec
  674. };
  675. /* Ozonic specification */
  676. static struct snd_bebob_meter_spec ozonic_meter_spec = {
  677. .num = ARRAY_SIZE(ozonic_meter_labels),
  678. .labels = ozonic_meter_labels,
  679. .get = &normal_meter_get
  680. };
  681. struct snd_bebob_spec maudio_ozonic_spec = {
  682. .clock = NULL,
  683. .rate = &usual_rate_spec,
  684. .meter = &ozonic_meter_spec
  685. };
  686. /* NRV10 specification */
  687. static struct snd_bebob_meter_spec nrv10_meter_spec = {
  688. .num = ARRAY_SIZE(nrv10_meter_labels),
  689. .labels = nrv10_meter_labels,
  690. .get = &normal_meter_get
  691. };
  692. struct snd_bebob_spec maudio_nrv10_spec = {
  693. .clock = NULL,
  694. .rate = &usual_rate_spec,
  695. .meter = &nrv10_meter_spec
  696. };