bebob_maudio.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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;
  90. /* check date of software used to build */
  91. err = snd_bebob_read_block(unit, INFO_OFFSET_SW_DATE,
  92. &date, sizeof(u64));
  93. if (err < 0)
  94. return err;
  95. /*
  96. * firmware version 5058 or later has date later than "20070401", but
  97. * 'date' is not null-terminated.
  98. */
  99. if (date < 0x3230303730343031LL) {
  100. dev_err(&unit->device,
  101. "Use firmware version 5058 or later\n");
  102. return -ENXIO;
  103. }
  104. cues = kmalloc_array(3, sizeof(*cues), GFP_KERNEL);
  105. if (!cues)
  106. return -ENOMEM;
  107. cues[0] = cpu_to_le32(MAUDIO_BOOTLOADER_CUE1);
  108. cues[1] = cpu_to_le32(MAUDIO_BOOTLOADER_CUE2);
  109. cues[2] = cpu_to_le32(MAUDIO_BOOTLOADER_CUE3);
  110. rcode = fw_run_transaction(device->card, TCODE_WRITE_BLOCK_REQUEST,
  111. device->node_id, device->generation,
  112. device->max_speed, BEBOB_ADDR_REG_REQ,
  113. cues, 3 * sizeof(*cues));
  114. kfree(cues);
  115. if (rcode != RCODE_COMPLETE) {
  116. dev_err(&unit->device,
  117. "Failed to send a cue to load firmware\n");
  118. err = -EIO;
  119. }
  120. return err;
  121. }
  122. static inline int
  123. get_meter(struct snd_bebob *bebob, void *buf, unsigned int size)
  124. {
  125. return snd_fw_transaction(bebob->unit, TCODE_READ_BLOCK_REQUEST,
  126. MAUDIO_SPECIFIC_ADDRESS + METER_OFFSET,
  127. buf, size, 0);
  128. }
  129. static int
  130. check_clk_sync(struct snd_bebob *bebob, unsigned int size, bool *sync)
  131. {
  132. int err;
  133. u8 *buf;
  134. buf = kmalloc(size, GFP_KERNEL);
  135. if (buf == NULL)
  136. return -ENOMEM;
  137. err = get_meter(bebob, buf, size);
  138. if (err < 0)
  139. goto end;
  140. /* if synced, this value is the same as SFC of FDF in CIP header */
  141. *sync = (buf[size - 2] != 0xff);
  142. end:
  143. kfree(buf);
  144. return err;
  145. }
  146. /*
  147. * dig_fmt: 0x00:S/PDIF, 0x01:ADAT
  148. * clk_lock: 0x00:unlock, 0x01:lock
  149. */
  150. static int
  151. avc_maudio_set_special_clk(struct snd_bebob *bebob, unsigned int clk_src,
  152. unsigned int dig_in_fmt, unsigned int dig_out_fmt,
  153. unsigned int clk_lock)
  154. {
  155. struct special_params *params = bebob->maudio_special_quirk;
  156. int err;
  157. u8 *buf;
  158. if (amdtp_stream_running(&bebob->rx_stream) ||
  159. amdtp_stream_running(&bebob->tx_stream))
  160. return -EBUSY;
  161. buf = kmalloc(12, GFP_KERNEL);
  162. if (buf == NULL)
  163. return -ENOMEM;
  164. buf[0] = 0x00; /* CONTROL */
  165. buf[1] = 0xff; /* UNIT */
  166. buf[2] = 0x00; /* vendor dependent */
  167. buf[3] = 0x04; /* company ID high */
  168. buf[4] = 0x00; /* company ID middle */
  169. buf[5] = 0x04; /* company ID low */
  170. buf[6] = 0xff & clk_src; /* clock source */
  171. buf[7] = 0xff & dig_in_fmt; /* input digital format */
  172. buf[8] = 0xff & dig_out_fmt; /* output digital format */
  173. buf[9] = 0xff & clk_lock; /* lock these settings */
  174. buf[10] = 0x00; /* padding */
  175. buf[11] = 0x00; /* padding */
  176. err = fcp_avc_transaction(bebob->unit, buf, 12, buf, 12,
  177. BIT(1) | BIT(2) | BIT(3) | BIT(4) |
  178. BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  179. BIT(9));
  180. if ((err > 0) && (err < 10))
  181. err = -EIO;
  182. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  183. err = -ENOSYS;
  184. else if (buf[0] == 0x0a) /* REJECTED */
  185. err = -EINVAL;
  186. if (err < 0)
  187. goto end;
  188. params->clk_src = buf[6];
  189. params->dig_in_fmt = buf[7];
  190. params->dig_out_fmt = buf[8];
  191. params->clk_lock = buf[9];
  192. if (params->ctl_id_sync)
  193. snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,
  194. params->ctl_id_sync);
  195. err = 0;
  196. end:
  197. kfree(buf);
  198. return err;
  199. }
  200. static void
  201. special_stream_formation_set(struct snd_bebob *bebob)
  202. {
  203. static const unsigned int ch_table[2][2][3] = {
  204. /* AMDTP_OUT_STREAM */
  205. { { 6, 6, 4 }, /* SPDIF */
  206. { 12, 8, 4 } }, /* ADAT */
  207. /* AMDTP_IN_STREAM */
  208. { { 10, 10, 2 }, /* SPDIF */
  209. { 16, 12, 2 } } /* ADAT */
  210. };
  211. struct special_params *params = bebob->maudio_special_quirk;
  212. unsigned int i, max;
  213. max = SND_BEBOB_STRM_FMT_ENTRIES - 1;
  214. if (!params->is1814)
  215. max -= 2;
  216. for (i = 0; i < max; i++) {
  217. bebob->tx_stream_formations[i + 1].pcm =
  218. ch_table[AMDTP_IN_STREAM][params->dig_in_fmt][i / 2];
  219. bebob->tx_stream_formations[i + 1].midi = 1;
  220. bebob->rx_stream_formations[i + 1].pcm =
  221. ch_table[AMDTP_OUT_STREAM][params->dig_out_fmt][i / 2];
  222. bebob->rx_stream_formations[i + 1].midi = 1;
  223. }
  224. }
  225. static int add_special_controls(struct snd_bebob *bebob);
  226. int
  227. snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
  228. {
  229. struct special_params *params;
  230. int err;
  231. params = kzalloc(sizeof(struct special_params), GFP_KERNEL);
  232. if (params == NULL)
  233. return -ENOMEM;
  234. mutex_lock(&bebob->mutex);
  235. bebob->maudio_special_quirk = (void *)params;
  236. params->is1814 = is1814;
  237. /* initialize these parameters because driver is not allowed to ask */
  238. bebob->rx_stream.context = ERR_PTR(-1);
  239. bebob->tx_stream.context = ERR_PTR(-1);
  240. err = avc_maudio_set_special_clk(bebob, 0x03, 0x00, 0x00, 0x00);
  241. if (err < 0) {
  242. dev_err(&bebob->unit->device,
  243. "fail to initialize clock params: %d\n", err);
  244. goto end;
  245. }
  246. err = add_special_controls(bebob);
  247. if (err < 0)
  248. goto end;
  249. special_stream_formation_set(bebob);
  250. if (params->is1814) {
  251. bebob->midi_input_ports = 1;
  252. bebob->midi_output_ports = 1;
  253. } else {
  254. bebob->midi_input_ports = 2;
  255. bebob->midi_output_ports = 2;
  256. }
  257. end:
  258. mutex_unlock(&bebob->mutex);
  259. return err;
  260. }
  261. /* Input plug shows actual rate. Output plug is needless for this purpose. */
  262. static int special_get_rate(struct snd_bebob *bebob, unsigned int *rate)
  263. {
  264. int err, trials;
  265. trials = 0;
  266. do {
  267. err = avc_general_get_sig_fmt(bebob->unit, rate,
  268. AVC_GENERAL_PLUG_DIR_IN, 0);
  269. } while (err == -EAGAIN && ++trials < 3);
  270. return err;
  271. }
  272. static int special_set_rate(struct snd_bebob *bebob, unsigned int rate)
  273. {
  274. struct special_params *params = bebob->maudio_special_quirk;
  275. int err;
  276. err = avc_general_set_sig_fmt(bebob->unit, rate,
  277. AVC_GENERAL_PLUG_DIR_OUT, 0);
  278. if (err < 0)
  279. goto end;
  280. /*
  281. * Just after changing sampling rate for output, a followed command
  282. * for input is easy to fail. This is a workaround fot this issue.
  283. */
  284. msleep(100);
  285. err = avc_general_set_sig_fmt(bebob->unit, rate,
  286. AVC_GENERAL_PLUG_DIR_IN, 0);
  287. if (err < 0)
  288. goto end;
  289. if (params->ctl_id_sync)
  290. snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,
  291. params->ctl_id_sync);
  292. end:
  293. return err;
  294. }
  295. /* Clock source control for special firmware */
  296. static const enum snd_bebob_clock_type special_clk_types[] = {
  297. SND_BEBOB_CLOCK_TYPE_INTERNAL, /* With digital mute */
  298. SND_BEBOB_CLOCK_TYPE_EXTERNAL, /* SPDIF/ADAT */
  299. SND_BEBOB_CLOCK_TYPE_EXTERNAL, /* Word Clock */
  300. SND_BEBOB_CLOCK_TYPE_INTERNAL,
  301. };
  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. static const char *const special_clk_labels[] = {
  312. "Internal with Digital Mute",
  313. "Digital",
  314. "Word Clock",
  315. "Internal"
  316. };
  317. return snd_ctl_enum_info(einf, 1, ARRAY_SIZE(special_clk_types),
  318. special_clk_labels);
  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_types))
  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 const 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 const 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 const 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. return snd_ctl_enum_info(einf, 1,
  391. ARRAY_SIZE(special_dig_in_iface_labels),
  392. special_dig_in_iface_labels);
  393. }
  394. static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
  395. struct snd_ctl_elem_value *uval)
  396. {
  397. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  398. struct special_params *params = bebob->maudio_special_quirk;
  399. unsigned int dig_in_iface;
  400. int err, val;
  401. mutex_lock(&bebob->mutex);
  402. err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,
  403. &dig_in_iface);
  404. if (err < 0) {
  405. dev_err(&bebob->unit->device,
  406. "fail to get digital input interface: %d\n", err);
  407. goto end;
  408. }
  409. /* encoded id for user value */
  410. val = (params->dig_in_fmt << 1) | (dig_in_iface & 0x01);
  411. /* for ADAT Optical */
  412. if (val > 2)
  413. val = 2;
  414. uval->value.enumerated.item[0] = val;
  415. end:
  416. mutex_unlock(&bebob->mutex);
  417. return err;
  418. }
  419. static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
  420. struct snd_ctl_elem_value *uval)
  421. {
  422. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  423. struct special_params *params = bebob->maudio_special_quirk;
  424. unsigned int id, dig_in_fmt, dig_in_iface;
  425. int err;
  426. id = uval->value.enumerated.item[0];
  427. if (id >= ARRAY_SIZE(special_dig_in_iface_labels))
  428. return -EINVAL;
  429. /* decode user value */
  430. dig_in_fmt = (id >> 1) & 0x01;
  431. dig_in_iface = id & 0x01;
  432. mutex_lock(&bebob->mutex);
  433. err = avc_maudio_set_special_clk(bebob,
  434. params->clk_src,
  435. dig_in_fmt,
  436. params->dig_out_fmt,
  437. params->clk_lock);
  438. if (err < 0)
  439. goto end;
  440. /* For ADAT, optical interface is only available. */
  441. if (params->dig_in_fmt > 0) {
  442. err = 1;
  443. goto end;
  444. }
  445. /* For S/PDIF, optical/coaxial interfaces are selectable. */
  446. err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);
  447. if (err < 0)
  448. dev_err(&bebob->unit->device,
  449. "fail to set digital input interface: %d\n", err);
  450. err = 1;
  451. end:
  452. special_stream_formation_set(bebob);
  453. mutex_unlock(&bebob->mutex);
  454. return err;
  455. }
  456. static const struct snd_kcontrol_new special_dig_in_iface_ctl = {
  457. .name = "Digital Input Interface",
  458. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  459. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  460. .info = special_dig_in_iface_ctl_info,
  461. .get = special_dig_in_iface_ctl_get,
  462. .put = special_dig_in_iface_ctl_set
  463. };
  464. /* Digital output interface control for special firmware */
  465. static const char *const special_dig_out_iface_labels[] = {
  466. "S/PDIF Optical and Coaxial", "ADAT Optical"
  467. };
  468. static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl,
  469. struct snd_ctl_elem_info *einf)
  470. {
  471. return snd_ctl_enum_info(einf, 1,
  472. ARRAY_SIZE(special_dig_out_iface_labels),
  473. special_dig_out_iface_labels);
  474. }
  475. static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
  476. struct snd_ctl_elem_value *uval)
  477. {
  478. struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
  479. struct special_params *params = bebob->maudio_special_quirk;
  480. mutex_lock(&bebob->mutex);
  481. uval->value.enumerated.item[0] = params->dig_out_fmt;
  482. mutex_unlock(&bebob->mutex);
  483. return 0;
  484. }
  485. static int special_dig_out_iface_ctl_set(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. unsigned int id;
  491. int err;
  492. id = uval->value.enumerated.item[0];
  493. if (id >= ARRAY_SIZE(special_dig_out_iface_labels))
  494. return -EINVAL;
  495. mutex_lock(&bebob->mutex);
  496. err = avc_maudio_set_special_clk(bebob,
  497. params->clk_src,
  498. params->dig_in_fmt,
  499. id, params->clk_lock);
  500. if (err >= 0) {
  501. special_stream_formation_set(bebob);
  502. err = 1;
  503. }
  504. mutex_unlock(&bebob->mutex);
  505. return err;
  506. }
  507. static const struct snd_kcontrol_new special_dig_out_iface_ctl = {
  508. .name = "Digital Output Interface",
  509. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  510. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  511. .info = special_dig_out_iface_ctl_info,
  512. .get = special_dig_out_iface_ctl_get,
  513. .put = special_dig_out_iface_ctl_set
  514. };
  515. static int add_special_controls(struct snd_bebob *bebob)
  516. {
  517. struct snd_kcontrol *kctl;
  518. struct special_params *params = bebob->maudio_special_quirk;
  519. int err;
  520. kctl = snd_ctl_new1(&special_clk_ctl, bebob);
  521. err = snd_ctl_add(bebob->card, kctl);
  522. if (err < 0)
  523. goto end;
  524. kctl = snd_ctl_new1(&special_sync_ctl, bebob);
  525. err = snd_ctl_add(bebob->card, kctl);
  526. if (err < 0)
  527. goto end;
  528. params->ctl_id_sync = &kctl->id;
  529. kctl = snd_ctl_new1(&special_dig_in_iface_ctl, bebob);
  530. err = snd_ctl_add(bebob->card, kctl);
  531. if (err < 0)
  532. goto end;
  533. kctl = snd_ctl_new1(&special_dig_out_iface_ctl, bebob);
  534. err = snd_ctl_add(bebob->card, kctl);
  535. end:
  536. return err;
  537. }
  538. /* Hardware metering for special firmware */
  539. static const char *const special_meter_labels[] = {
  540. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  541. SPDIF_IN,
  542. ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN,
  543. ANA_OUT, ANA_OUT,
  544. SPDIF_OUT,
  545. ADAT_OUT, ADAT_OUT, ADAT_OUT, ADAT_OUT,
  546. HP_OUT, HP_OUT,
  547. AUX_OUT
  548. };
  549. static int
  550. special_meter_get(struct snd_bebob *bebob, u32 *target, unsigned int size)
  551. {
  552. __be16 *buf;
  553. unsigned int i, c, channels;
  554. int err;
  555. channels = ARRAY_SIZE(special_meter_labels) * 2;
  556. if (size < channels * sizeof(u32))
  557. return -EINVAL;
  558. /* omit last 4 bytes because it's clock info. */
  559. buf = kmalloc(METER_SIZE_SPECIAL - 4, GFP_KERNEL);
  560. if (buf == NULL)
  561. return -ENOMEM;
  562. err = get_meter(bebob, (void *)buf, METER_SIZE_SPECIAL - 4);
  563. if (err < 0)
  564. goto end;
  565. /* Its format is u16 and some channels are unknown. */
  566. i = 0;
  567. for (c = 2; c < channels + 2; c++)
  568. target[i++] = be16_to_cpu(buf[c]) << 16;
  569. end:
  570. kfree(buf);
  571. return err;
  572. }
  573. /* last 4 bytes are omitted because it's clock info. */
  574. static const char *const fw410_meter_labels[] = {
  575. ANA_IN, DIG_IN,
  576. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT,
  577. HP_OUT
  578. };
  579. static const char *const audiophile_meter_labels[] = {
  580. ANA_IN, DIG_IN,
  581. ANA_OUT, ANA_OUT, DIG_OUT,
  582. HP_OUT, AUX_OUT,
  583. };
  584. static const char *const solo_meter_labels[] = {
  585. ANA_IN, DIG_IN,
  586. STRM_IN, STRM_IN,
  587. ANA_OUT, DIG_OUT
  588. };
  589. /* no clock info */
  590. static const char *const ozonic_meter_labels[] = {
  591. ANA_IN, ANA_IN,
  592. STRM_IN, STRM_IN,
  593. ANA_OUT, ANA_OUT
  594. };
  595. /* TODO: need testers. these positions are based on authour's assumption */
  596. static const char *const nrv10_meter_labels[] = {
  597. ANA_IN, ANA_IN, ANA_IN, ANA_IN,
  598. DIG_IN,
  599. ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
  600. DIG_IN
  601. };
  602. static int
  603. normal_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)
  604. {
  605. const struct snd_bebob_meter_spec *spec = bebob->spec->meter;
  606. unsigned int c, channels;
  607. int err;
  608. channels = spec->num * 2;
  609. if (size < channels * sizeof(u32))
  610. return -EINVAL;
  611. err = get_meter(bebob, (void *)buf, size);
  612. if (err < 0)
  613. goto end;
  614. for (c = 0; c < channels; c++)
  615. be32_to_cpus(&buf[c]);
  616. /* swap stream channels because inverted */
  617. if (spec->labels == solo_meter_labels) {
  618. swap(buf[4], buf[6]);
  619. swap(buf[5], buf[7]);
  620. }
  621. end:
  622. return err;
  623. }
  624. /* for special customized devices */
  625. static const struct snd_bebob_rate_spec special_rate_spec = {
  626. .get = &special_get_rate,
  627. .set = &special_set_rate,
  628. };
  629. static const struct snd_bebob_clock_spec special_clk_spec = {
  630. .num = ARRAY_SIZE(special_clk_types),
  631. .types = special_clk_types,
  632. .get = &special_clk_get,
  633. };
  634. static const struct snd_bebob_meter_spec special_meter_spec = {
  635. .num = ARRAY_SIZE(special_meter_labels),
  636. .labels = special_meter_labels,
  637. .get = &special_meter_get
  638. };
  639. const struct snd_bebob_spec maudio_special_spec = {
  640. .clock = &special_clk_spec,
  641. .rate = &special_rate_spec,
  642. .meter = &special_meter_spec
  643. };
  644. /* Firewire 410 specification */
  645. static const struct snd_bebob_rate_spec usual_rate_spec = {
  646. .get = &snd_bebob_stream_get_rate,
  647. .set = &snd_bebob_stream_set_rate,
  648. };
  649. static const struct snd_bebob_meter_spec fw410_meter_spec = {
  650. .num = ARRAY_SIZE(fw410_meter_labels),
  651. .labels = fw410_meter_labels,
  652. .get = &normal_meter_get
  653. };
  654. const struct snd_bebob_spec maudio_fw410_spec = {
  655. .clock = NULL,
  656. .rate = &usual_rate_spec,
  657. .meter = &fw410_meter_spec
  658. };
  659. /* Firewire Audiophile specification */
  660. static const struct snd_bebob_meter_spec audiophile_meter_spec = {
  661. .num = ARRAY_SIZE(audiophile_meter_labels),
  662. .labels = audiophile_meter_labels,
  663. .get = &normal_meter_get
  664. };
  665. const struct snd_bebob_spec maudio_audiophile_spec = {
  666. .clock = NULL,
  667. .rate = &usual_rate_spec,
  668. .meter = &audiophile_meter_spec
  669. };
  670. /* Firewire Solo specification */
  671. static const struct snd_bebob_meter_spec solo_meter_spec = {
  672. .num = ARRAY_SIZE(solo_meter_labels),
  673. .labels = solo_meter_labels,
  674. .get = &normal_meter_get
  675. };
  676. const struct snd_bebob_spec maudio_solo_spec = {
  677. .clock = NULL,
  678. .rate = &usual_rate_spec,
  679. .meter = &solo_meter_spec
  680. };
  681. /* Ozonic specification */
  682. static const struct snd_bebob_meter_spec ozonic_meter_spec = {
  683. .num = ARRAY_SIZE(ozonic_meter_labels),
  684. .labels = ozonic_meter_labels,
  685. .get = &normal_meter_get
  686. };
  687. const struct snd_bebob_spec maudio_ozonic_spec = {
  688. .clock = NULL,
  689. .rate = &usual_rate_spec,
  690. .meter = &ozonic_meter_spec
  691. };
  692. /* NRV10 specification */
  693. static const struct snd_bebob_meter_spec nrv10_meter_spec = {
  694. .num = ARRAY_SIZE(nrv10_meter_labels),
  695. .labels = nrv10_meter_labels,
  696. .get = &normal_meter_get
  697. };
  698. const struct snd_bebob_spec maudio_nrv10_spec = {
  699. .clock = NULL,
  700. .rate = &usual_rate_spec,
  701. .meter = &nrv10_meter_spec
  702. };