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