bebob_maudio.c 21 KB

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