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