Lines Matching +full:num +full:- +full:ports

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2018-2019 by Geoffrey D. Bennett <g at b4.vu>
28 * (firmware 1083) using usbmon in July-August 2018.
36 * - input, output, mixer-matrix muxes
37 * - 18x10 mixer-matrix gain stages
38 * - gain/volume controls
39 * - level meters
40 * - line/inst level and pad controls
43 * /--------------\ 18chn 20chn /--------------\
44 * | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
45 * \--------------/ | | | | \--------------/
46 * | | | /-----\ |
49 * | +---------------+ | |
51 * | +-----+-----+ | |
57 * | +------------+ | |
63 * | +-----+------+ | |
67 * | +----------/ |
71 * +---------------+ +--------------+
73 * +---+---+---+ +-----+-----+
77 * /--------------\ | | | /--------------\
78 * | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
79 * | Hardware out | | \--------------/
80 * \--------------/ |
82 * +-------------+ Software gain per channel.
83 * | Master Gain |<-- 18i20 only: Switch per channel
84 * +------+------+ to select HW or SW gain control.
87 * /--------------\ |
88 * | Analogue |<------/
90 * \--------------/
114 /* mixer range from -80dB to +6dB in 0.5dB steps */
115 #define SCARLETT2_MIXER_MIN_DB -80
116 #define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
119 ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
122 * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
165 * - None (no input to mux)
166 * - Analogue I/O
167 * - S/PDIF I/O
168 * - ADAT I/O
169 * - Mixer I/O
170 * - PCM I/O
200 * - id: hardware ID for this port type
201 * - num: number of sources/destinations of this port type
202 * - src_descr: printf format string for mux input selections
203 * - src_num_offset: added to channel number for the fprintf
204 * - dst_descr: printf format string for mixer controls
208 int num[SCARLETT2_PORT_DIRECTIONS]; member
220 struct scarlett2_ports ports[SCARLETT2_PORT_TYPE_COUNT]; member
245 /*** Model-specific data ***/
263 .ports = {
266 .num = { 1, 0, 8, 8, 8 },
272 .num = { 4, 4, 4, 4, 4 },
279 .num = { 2, 2, 2, 2, 2 },
286 .num = { 10, 18, 18, 18, 18 },
293 .num = { 6, 6, 6, 6, 6 },
319 .ports = {
322 .num = { 1, 0, 8, 8, 4 },
328 .num = { 8, 6, 6, 6, 6 },
339 .num = { 2, 2, 2, 2, 2 },
346 .num = { 8, 0, 0, 0, 0 },
352 .num = { 10, 18, 18, 18, 18 },
359 .num = { 20, 18, 18, 14, 10 },
389 .ports = {
392 .num = { 1, 0, 8, 8, 6 },
398 .num = { 8, 10, 10, 10, 10 },
409 .num = { 2, 2, 2, 2, 2 },
416 .num = { 8, 8, 8, 4, 0 },
423 .num = { 10, 18, 18, 18, 18 },
430 .num = { 20, 18, 18, 14, 10 },
439 static int scarlett2_get_port_start_num(const struct scarlett2_ports *ports, in scarlett2_get_port_start_num() argument
442 int i, num = 0; in scarlett2_get_port_start_num() local
445 num += ports[i].num[direction]; in scarlett2_get_port_start_num()
447 return num; in scarlett2_get_port_start_num()
452 /* Vendor-Specific Interface, Endpoint, MaxPacketSize, Interval */
488 /* actual volume of output inc. dim (-18dB) */
576 u16 seq = private->scarlett2_seq++; in scarlett2_fill_request_header()
578 req->cmd = cpu_to_le32(cmd); in scarlett2_fill_request_header()
579 req->size = cpu_to_le16(req_size); in scarlett2_fill_request_header()
580 req->seq = cpu_to_le16(seq); in scarlett2_fill_request_header()
581 req->error = 0; in scarlett2_fill_request_header()
582 req->pad = 0; in scarlett2_fill_request_header()
590 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_usb()
598 err = -ENOMEM; in scarlett2_usb()
604 err = -ENOMEM; in scarlett2_usb()
608 mutex_lock(&private->usb_mutex); in scarlett2_usb()
615 memcpy(req->data, req_data, req_size); in scarlett2_usb()
617 err = snd_usb_ctl_msg(mixer->chip->dev, in scarlett2_usb()
618 usb_sndctrlpipe(mixer->chip->dev, 0), in scarlett2_usb()
628 mixer->chip, in scarlett2_usb()
631 err = -EINVAL; in scarlett2_usb()
637 err = snd_usb_ctl_msg(mixer->chip->dev, in scarlett2_usb()
638 usb_sndctrlpipe(mixer->chip->dev, 0), in scarlett2_usb()
650 mixer->chip, in scarlett2_usb()
653 err = -EINVAL; in scarlett2_usb()
657 if (resp->cmd != req->cmd || in scarlett2_usb()
658 resp->seq != req->seq || in scarlett2_usb()
659 resp_size != le16_to_cpu(resp->size) || in scarlett2_usb()
660 resp->error || in scarlett2_usb()
661 resp->pad) { in scarlett2_usb()
663 mixer->chip, in scarlett2_usb()
667 le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd), in scarlett2_usb()
668 le16_to_cpu(req->seq), le16_to_cpu(resp->seq), in scarlett2_usb()
669 resp_size, le16_to_cpu(resp->size), in scarlett2_usb()
670 le32_to_cpu(resp->error), in scarlett2_usb()
671 le32_to_cpu(resp->pad)); in scarlett2_usb()
672 err = -EINVAL; in scarlett2_usb()
677 memcpy(resp_data, resp->data, resp_size); in scarlett2_usb()
680 mutex_unlock(&private->usb_mutex); in scarlett2_usb()
703 scarlett2_config_save(private->mixer); in scarlett2_config_save_work()
722 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_usb_set_config()
725 cancel_delayed_work_sync(&private->work); in scarlett2_usb_set_config()
745 schedule_delayed_work(&private->work, msecs_to_jiffies(2000)); in scarlett2_usb_set_config()
788 * (values obtained from private->mix[])
793 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_usb_set_mix()
794 const struct scarlett2_device_info *info = private->info; in scarlett2_usb_set_mix()
803 info->ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT]; in scarlett2_usb_set_mix()
809 scarlett2_mixer_values[private->mix[j]] in scarlett2_usb_set_mix()
817 /* Convert a port number index (per info->ports) to a hardware ID */
818 static u32 scarlett2_mux_src_num_to_id(const struct scarlett2_ports *ports, in scarlett2_mux_src_num_to_id() argument
819 int num) in scarlett2_mux_src_num_to_id() argument
826 if (num < ports[port_type].num[SCARLETT2_PORT_IN]) in scarlett2_mux_src_num_to_id()
827 return ports[port_type].id | num; in scarlett2_mux_src_num_to_id()
828 num -= ports[port_type].num[SCARLETT2_PORT_IN]; in scarlett2_mux_src_num_to_id()
838 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_usb_set_mux()
839 const struct scarlett2_device_info *info = private->info; in scarlett2_usb_set_mux()
840 const struct scarlett2_ports *ports = info->ports; in scarlett2_usb_set_mux() local
854 __le16 num; in scarlett2_usb_set_mux() member
866 req.num = cpu_to_le16(rate); in scarlett2_usb_set_mux()
872 int j = scarlett2_get_port_start_num(ports, in scarlett2_usb_set_mux()
875 int port_id = ports[port_type].id; in scarlett2_usb_set_mux()
879 channel < ports[port_type].num[port_dir_rate]; in scarlett2_usb_set_mux()
890 ports, private->mux[j] in scarlett2_usb_set_mux()
894 /* skip private->mux[j] entries not output */ in scarlett2_usb_set_mux()
895 j += ports[port_type].num[SCARLETT2_PORT_OUT] - in scarlett2_usb_set_mux()
896 ports[port_type].num[port_dir_rate]; in scarlett2_usb_set_mux()
950 return -ENOMEM; in scarlett2_add_new_ctl()
952 elem->head.mixer = mixer; in scarlett2_add_new_ctl()
953 elem->control = index; in scarlett2_add_new_ctl()
954 elem->head.id = index; in scarlett2_add_new_ctl()
955 elem->channels = channels; in scarlett2_add_new_ctl()
960 return -ENOMEM; in scarlett2_add_new_ctl()
962 kctl->private_free = snd_usb_mixer_elem_free; in scarlett2_add_new_ctl()
964 strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); in scarlett2_add_new_ctl()
966 err = snd_usb_mixer_add_control(&elem->head, kctl); in scarlett2_add_new_ctl()
983 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_update_volumes()
984 const struct scarlett2_ports *ports = private->info->ports; in scarlett2_update_volumes() local
987 ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT]; in scarlett2_update_volumes()
990 private->vol_updated = 0; in scarlett2_update_volumes()
996 private->master_vol = clamp( in scarlett2_update_volumes()
1001 if (private->vol_sw_hw_switch[i]) in scarlett2_update_volumes()
1002 private->vol[i] = private->master_vol; in scarlett2_update_volumes()
1005 for (i = 0; i < private->info->button_count; i++) in scarlett2_update_volumes()
1006 private->buttons[i] = !!volume_status.buttons[i]; in scarlett2_update_volumes()
1014 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_volume_ctl_info()
1016 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in scarlett2_volume_ctl_info()
1017 uinfo->count = elem->channels; in scarlett2_volume_ctl_info()
1018 uinfo->value.integer.min = 0; in scarlett2_volume_ctl_info()
1019 uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS; in scarlett2_volume_ctl_info()
1020 uinfo->value.integer.step = 1; in scarlett2_volume_ctl_info()
1027 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_master_volume_ctl_get()
1028 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_master_volume_ctl_get()
1029 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_master_volume_ctl_get()
1031 if (private->vol_updated) { in scarlett2_master_volume_ctl_get()
1032 mutex_lock(&private->data_mutex); in scarlett2_master_volume_ctl_get()
1034 mutex_unlock(&private->data_mutex); in scarlett2_master_volume_ctl_get()
1037 ucontrol->value.integer.value[0] = private->master_vol; in scarlett2_master_volume_ctl_get()
1044 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_volume_ctl_get()
1045 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_volume_ctl_get()
1046 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_volume_ctl_get()
1047 int index = elem->control; in scarlett2_volume_ctl_get()
1049 if (private->vol_updated) { in scarlett2_volume_ctl_get()
1050 mutex_lock(&private->data_mutex); in scarlett2_volume_ctl_get()
1052 mutex_unlock(&private->data_mutex); in scarlett2_volume_ctl_get()
1055 ucontrol->value.integer.value[0] = private->vol[index]; in scarlett2_volume_ctl_get()
1062 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_volume_ctl_put()
1063 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_volume_ctl_put()
1064 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_volume_ctl_put()
1065 int index = elem->control; in scarlett2_volume_ctl_put()
1068 mutex_lock(&private->data_mutex); in scarlett2_volume_ctl_put()
1070 oval = private->vol[index]; in scarlett2_volume_ctl_put()
1071 val = ucontrol->value.integer.value[0]; in scarlett2_volume_ctl_put()
1076 private->vol[index] = val; in scarlett2_volume_ctl_put()
1078 index, val - SCARLETT2_VOLUME_BIAS); in scarlett2_volume_ctl_put()
1083 mutex_unlock(&private->data_mutex); in scarlett2_volume_ctl_put()
1088 db_scale_scarlett2_gain, -SCARLETT2_VOLUME_BIAS * 100, 0
1129 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_sw_hw_enum_ctl_get()
1130 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_sw_hw_enum_ctl_get()
1132 ucontrol->value.enumerated.item[0] = in scarlett2_sw_hw_enum_ctl_get()
1133 private->vol_sw_hw_switch[elem->control]; in scarlett2_sw_hw_enum_ctl_get()
1140 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_sw_hw_enum_ctl_put()
1141 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_sw_hw_enum_ctl_put()
1142 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_sw_hw_enum_ctl_put()
1144 int index = elem->control; in scarlett2_sw_hw_enum_ctl_put()
1147 mutex_lock(&private->data_mutex); in scarlett2_sw_hw_enum_ctl_put()
1149 oval = private->vol_sw_hw_switch[index]; in scarlett2_sw_hw_enum_ctl_put()
1150 val = !!ucontrol->value.integer.value[0]; in scarlett2_sw_hw_enum_ctl_put()
1155 private->vol_sw_hw_switch[index] = val; in scarlett2_sw_hw_enum_ctl_put()
1161 private->vol_ctls[index]->vd[0].access &= in scarlett2_sw_hw_enum_ctl_put()
1164 private->vol_ctls[index]->vd[0].access |= in scarlett2_sw_hw_enum_ctl_put()
1168 private->vol[index] = private->master_vol; in scarlett2_sw_hw_enum_ctl_put()
1173 index, private->master_vol - SCARLETT2_VOLUME_BIAS); in scarlett2_sw_hw_enum_ctl_put()
1178 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_INFO, in scarlett2_sw_hw_enum_ctl_put()
1179 &private->vol_ctls[index]->id); in scarlett2_sw_hw_enum_ctl_put()
1186 mutex_unlock(&private->data_mutex); in scarlett2_sw_hw_enum_ctl_put()
1213 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_level_enum_ctl_get()
1214 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_level_enum_ctl_get()
1216 ucontrol->value.enumerated.item[0] = in scarlett2_level_enum_ctl_get()
1217 private->level_switch[elem->control]; in scarlett2_level_enum_ctl_get()
1224 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_level_enum_ctl_put()
1225 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_level_enum_ctl_put()
1226 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_level_enum_ctl_put()
1228 int index = elem->control; in scarlett2_level_enum_ctl_put()
1231 mutex_lock(&private->data_mutex); in scarlett2_level_enum_ctl_put()
1233 oval = private->level_switch[index]; in scarlett2_level_enum_ctl_put()
1234 val = !!ucontrol->value.integer.value[0]; in scarlett2_level_enum_ctl_put()
1239 private->level_switch[index] = val; in scarlett2_level_enum_ctl_put()
1246 mutex_unlock(&private->data_mutex); in scarlett2_level_enum_ctl_put()
1263 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_pad_ctl_get()
1264 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_pad_ctl_get()
1266 ucontrol->value.enumerated.item[0] = in scarlett2_pad_ctl_get()
1267 private->pad_switch[elem->control]; in scarlett2_pad_ctl_get()
1274 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_pad_ctl_put()
1275 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_pad_ctl_put()
1276 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_pad_ctl_put()
1278 int index = elem->control; in scarlett2_pad_ctl_put()
1281 mutex_lock(&private->data_mutex); in scarlett2_pad_ctl_put()
1283 oval = private->pad_switch[index]; in scarlett2_pad_ctl_put()
1284 val = !!ucontrol->value.integer.value[0]; in scarlett2_pad_ctl_put()
1289 private->pad_switch[index] = val; in scarlett2_pad_ctl_put()
1296 mutex_unlock(&private->data_mutex); in scarlett2_pad_ctl_put()
1313 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_button_ctl_get()
1314 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_button_ctl_get()
1315 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_button_ctl_get()
1317 if (private->vol_updated) { in scarlett2_button_ctl_get()
1318 mutex_lock(&private->data_mutex); in scarlett2_button_ctl_get()
1320 mutex_unlock(&private->data_mutex); in scarlett2_button_ctl_get()
1323 ucontrol->value.enumerated.item[0] = private->buttons[elem->control]; in scarlett2_button_ctl_get()
1330 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_button_ctl_put()
1331 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_button_ctl_put()
1332 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_button_ctl_put()
1334 int index = elem->control; in scarlett2_button_ctl_put()
1337 mutex_lock(&private->data_mutex); in scarlett2_button_ctl_put()
1339 oval = private->buttons[index]; in scarlett2_button_ctl_put()
1340 val = !!ucontrol->value.integer.value[0]; in scarlett2_button_ctl_put()
1345 private->buttons[index] = val; in scarlett2_button_ctl_put()
1352 mutex_unlock(&private->data_mutex); in scarlett2_button_ctl_put()
1368 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_add_line_out_ctls()
1369 const struct scarlett2_device_info *info = private->info; in scarlett2_add_line_out_ctls()
1370 const struct scarlett2_ports *ports = info->ports; in scarlett2_add_line_out_ctls() local
1372 ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT]; in scarlett2_add_line_out_ctls()
1377 if (info->line_out_hw_vol) { in scarlett2_add_line_out_ctls()
1381 0, 1, s, &private->master_vol_ctl); in scarlett2_add_line_out_ctls()
1390 if (info->line_out_descrs[i]) in scarlett2_add_line_out_ctls()
1393 i + 1, info->line_out_descrs[i]); in scarlett2_add_line_out_ctls()
1400 i, 1, s, &private->vol_ctls[i]); in scarlett2_add_line_out_ctls()
1404 /* Make the fader read-only if the SW/HW switch is set to HW */ in scarlett2_add_line_out_ctls()
1405 if (private->vol_sw_hw_switch[i]) in scarlett2_add_line_out_ctls()
1406 private->vol_ctls[i]->vd[0].access &= in scarlett2_add_line_out_ctls()
1410 if (info->line_out_hw_vol) { in scarlett2_add_line_out_ctls()
1423 for (i = 0; i < private->info->button_count; i++) { in scarlett2_add_line_out_ctls()
1426 &private->button_ctls[i]); in scarlett2_add_line_out_ctls()
1438 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_add_line_in_ctls()
1439 const struct scarlett2_device_info *info = private->info; in scarlett2_add_line_in_ctls()
1444 for (i = 0; i < info->level_input_count; i++) { in scarlett2_add_line_in_ctls()
1453 for (i = 0; i < info->pad_input_count; i++) { in scarlett2_add_line_in_ctls()
1469 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mixer_ctl_info()
1471 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in scarlett2_mixer_ctl_info()
1472 uinfo->count = elem->channels; in scarlett2_mixer_ctl_info()
1473 uinfo->value.integer.min = 0; in scarlett2_mixer_ctl_info()
1474 uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE; in scarlett2_mixer_ctl_info()
1475 uinfo->value.integer.step = 1; in scarlett2_mixer_ctl_info()
1482 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mixer_ctl_get()
1483 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_mixer_ctl_get()
1485 ucontrol->value.integer.value[0] = private->mix[elem->control]; in scarlett2_mixer_ctl_get()
1492 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mixer_ctl_put()
1493 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_mixer_ctl_put()
1494 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_mixer_ctl_put()
1495 const struct scarlett2_device_info *info = private->info; in scarlett2_mixer_ctl_put()
1496 const struct scarlett2_ports *ports = info->ports; in scarlett2_mixer_ctl_put() local
1499 mutex_lock(&private->data_mutex); in scarlett2_mixer_ctl_put()
1501 oval = private->mix[elem->control]; in scarlett2_mixer_ctl_put()
1502 val = ucontrol->value.integer.value[0]; in scarlett2_mixer_ctl_put()
1503 num_mixer_in = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT]; in scarlett2_mixer_ctl_put()
1504 mix_num = elem->control / num_mixer_in; in scarlett2_mixer_ctl_put()
1509 private->mix[elem->control] = val; in scarlett2_mixer_ctl_put()
1515 mutex_unlock(&private->data_mutex); in scarlett2_mixer_ctl_put()
1539 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_add_mixer_ctls()
1540 const struct scarlett2_ports *ports = private->info->ports; in scarlett2_add_mixer_ctls() local
1545 int num_inputs = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT]; in scarlett2_add_mixer_ctls()
1546 int num_outputs = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_IN]; in scarlett2_add_mixer_ctls()
1568 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mux_src_enum_ctl_info()
1569 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_mux_src_enum_ctl_info()
1570 const struct scarlett2_ports *ports = private->info->ports; in scarlett2_mux_src_enum_ctl_info() local
1571 unsigned int item = uinfo->value.enumerated.item; in scarlett2_mux_src_enum_ctl_info()
1572 int items = private->num_mux_srcs; in scarlett2_mux_src_enum_ctl_info()
1575 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; in scarlett2_mux_src_enum_ctl_info()
1576 uinfo->count = elem->channels; in scarlett2_mux_src_enum_ctl_info()
1577 uinfo->value.enumerated.items = items; in scarlett2_mux_src_enum_ctl_info()
1580 item = uinfo->value.enumerated.item = items - 1; in scarlett2_mux_src_enum_ctl_info()
1585 if (item < ports[port_type].num[SCARLETT2_PORT_IN]) { in scarlett2_mux_src_enum_ctl_info()
1586 sprintf(uinfo->value.enumerated.name, in scarlett2_mux_src_enum_ctl_info()
1587 ports[port_type].src_descr, in scarlett2_mux_src_enum_ctl_info()
1588 item + ports[port_type].src_num_offset); in scarlett2_mux_src_enum_ctl_info()
1591 item -= ports[port_type].num[SCARLETT2_PORT_IN]; in scarlett2_mux_src_enum_ctl_info()
1594 return -EINVAL; in scarlett2_mux_src_enum_ctl_info()
1600 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mux_src_enum_ctl_get()
1601 struct scarlett2_mixer_data *private = elem->head.mixer->private_data; in scarlett2_mux_src_enum_ctl_get()
1603 ucontrol->value.enumerated.item[0] = private->mux[elem->control]; in scarlett2_mux_src_enum_ctl_get()
1610 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_mux_src_enum_ctl_put()
1611 struct usb_mixer_interface *mixer = elem->head.mixer; in scarlett2_mux_src_enum_ctl_put()
1612 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_mux_src_enum_ctl_put()
1613 int index = elem->control; in scarlett2_mux_src_enum_ctl_put()
1616 mutex_lock(&private->data_mutex); in scarlett2_mux_src_enum_ctl_put()
1618 oval = private->mux[index]; in scarlett2_mux_src_enum_ctl_put()
1619 val = clamp(ucontrol->value.integer.value[0], in scarlett2_mux_src_enum_ctl_put()
1620 0L, private->num_mux_srcs - 1L); in scarlett2_mux_src_enum_ctl_put()
1625 private->mux[index] = val; in scarlett2_mux_src_enum_ctl_put()
1631 mutex_unlock(&private->data_mutex); in scarlett2_mux_src_enum_ctl_put()
1645 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_add_mux_enums()
1646 const struct scarlett2_ports *ports = private->info->ports; in scarlett2_add_mux_enums() local
1653 channel < ports[port_type].num[SCARLETT2_PORT_OUT]; in scarlett2_add_mux_enums()
1657 const char *const descr = ports[port_type].dst_descr; in scarlett2_add_mux_enums()
1659 snprintf(s, sizeof(s) - 5, descr, channel + 1); in scarlett2_add_mux_enums()
1678 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_meter_ctl_info()
1680 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in scarlett2_meter_ctl_info()
1681 uinfo->count = elem->channels; in scarlett2_meter_ctl_info()
1682 uinfo->value.integer.min = 0; in scarlett2_meter_ctl_info()
1683 uinfo->value.integer.max = 4095; in scarlett2_meter_ctl_info()
1684 uinfo->value.integer.step = 1; in scarlett2_meter_ctl_info()
1691 struct usb_mixer_elem_info *elem = kctl->private_data; in scarlett2_meter_ctl_get()
1695 err = scarlett2_usb_get_meter_levels(elem->head.mixer, meter_levels); in scarlett2_meter_ctl_get()
1699 for (i = 0; i < elem->channels; i++) in scarlett2_meter_ctl_get()
1700 ucontrol->value.integer.value[i] = meter_levels[i]; in scarlett2_meter_ctl_get()
1724 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_private_free()
1726 cancel_delayed_work_sync(&private->work); in scarlett2_private_free()
1728 mixer->private_data = NULL; in scarlett2_private_free()
1733 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_private_suspend()
1735 if (cancel_delayed_work_sync(&private->work)) in scarlett2_private_suspend()
1736 scarlett2_config_save(private->mixer); in scarlett2_private_suspend()
1741 static int scarlett2_count_mux_srcs(const struct scarlett2_ports *ports) in scarlett2_count_mux_srcs() argument
1748 count += ports[port_type].num[SCARLETT2_PORT_IN]; in scarlett2_count_mux_srcs()
1757 const struct scarlett2_ports *ports) in scarlett2_init_routing() argument
1766 -1 in scarlett2_init_routing()
1770 output_num = scarlett2_get_port_start_num(ports, in scarlett2_init_routing()
1773 output_count = ports[SCARLETT2_PORT_TYPE_PCM].num[SCARLETT2_PORT_OUT]; in scarlett2_init_routing()
1779 ports, SCARLETT2_PORT_IN, port_type); in scarlett2_init_routing()
1780 input_count = ports[port_type].num[SCARLETT2_PORT_IN]; in scarlett2_init_routing()
1783 i++, output_count--) in scarlett2_init_routing()
1788 input_num = scarlett2_get_port_start_num(ports, in scarlett2_init_routing()
1791 input_count = ports[SCARLETT2_PORT_TYPE_PCM].num[SCARLETT2_PORT_IN]; in scarlett2_init_routing()
1797 ports, SCARLETT2_PORT_OUT, port_type); in scarlett2_init_routing()
1798 output_count = ports[port_type].num[SCARLETT2_PORT_OUT]; in scarlett2_init_routing()
1801 i++, input_count--) in scarlett2_init_routing()
1814 return -ENOMEM; in scarlett2_init_private()
1816 mutex_init(&private->usb_mutex); in scarlett2_init_private()
1817 mutex_init(&private->data_mutex); in scarlett2_init_private()
1818 INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work); in scarlett2_init_private()
1819 private->info = info; in scarlett2_init_private()
1820 private->num_mux_srcs = scarlett2_count_mux_srcs(info->ports); in scarlett2_init_private()
1821 private->scarlett2_seq = 0; in scarlett2_init_private()
1822 private->mixer = mixer; in scarlett2_init_private()
1823 mixer->private_data = private; in scarlett2_init_private()
1824 mixer->private_free = scarlett2_private_free; in scarlett2_init_private()
1825 mixer->private_suspend = scarlett2_private_suspend; in scarlett2_init_private()
1828 scarlett2_init_routing(private->mux, info->ports); in scarlett2_init_private()
1834 /* Read line-in config and line-out volume settings on start */
1837 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_read_configs()
1838 const struct scarlett2_device_info *info = private->info; in scarlett2_read_configs()
1839 const struct scarlett2_ports *ports = info->ports; in scarlett2_read_configs() local
1841 ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT]; in scarlett2_read_configs()
1847 if (info->level_input_count) { in scarlett2_read_configs()
1851 info->level_input_count, in scarlett2_read_configs()
1855 for (i = 0; i < info->level_input_count; i++) in scarlett2_read_configs()
1856 private->level_switch[i] = level_switches[i]; in scarlett2_read_configs()
1859 if (info->pad_input_count) { in scarlett2_read_configs()
1863 info->pad_input_count, in scarlett2_read_configs()
1867 for (i = 0; i < info->pad_input_count; i++) in scarlett2_read_configs()
1868 private->pad_switch[i] = pad_switches[i]; in scarlett2_read_configs()
1875 private->master_vol = clamp( in scarlett2_read_configs()
1882 private->vol_sw_hw_switch[i] = in scarlett2_read_configs()
1883 info->line_out_hw_vol in scarlett2_read_configs()
1886 volume = private->vol_sw_hw_switch[i] in scarlett2_read_configs()
1891 private->vol[i] = volume; in scarlett2_read_configs()
1894 for (i = 0; i < info->button_count; i++) in scarlett2_read_configs()
1895 private->buttons[i] = !!volume_status.buttons[i]; in scarlett2_read_configs()
1904 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_mixer_interrupt_vol_change()
1905 const struct scarlett2_ports *ports = private->info->ports; in scarlett2_mixer_interrupt_vol_change() local
1907 ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT]; in scarlett2_mixer_interrupt_vol_change()
1910 private->vol_updated = 1; in scarlett2_mixer_interrupt_vol_change()
1912 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in scarlett2_mixer_interrupt_vol_change()
1913 &private->master_vol_ctl->id); in scarlett2_mixer_interrupt_vol_change()
1916 if (!private->vol_sw_hw_switch[i]) in scarlett2_mixer_interrupt_vol_change()
1918 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in scarlett2_mixer_interrupt_vol_change()
1919 &private->vol_ctls[i]->id); in scarlett2_mixer_interrupt_vol_change()
1927 struct scarlett2_mixer_data *private = mixer->private_data; in scarlett2_mixer_interrupt_button_change()
1930 private->vol_updated = 1; in scarlett2_mixer_interrupt_button_change()
1932 for (i = 0; i < private->info->button_count; i++) in scarlett2_mixer_interrupt_button_change()
1933 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in scarlett2_mixer_interrupt_button_change()
1934 &private->button_ctls[i]->id); in scarlett2_mixer_interrupt_button_change()
1940 struct usb_mixer_interface *mixer = urb->context; in scarlett2_mixer_interrupt()
1941 int len = urb->actual_length; in scarlett2_mixer_interrupt()
1942 int ustatus = urb->status; in scarlett2_mixer_interrupt()
1949 data = le32_to_cpu(*(__le32 *)urb->transfer_buffer); in scarlett2_mixer_interrupt()
1955 usb_audio_err(mixer->chip, in scarlett2_mixer_interrupt()
1960 if (ustatus != -ENOENT && in scarlett2_mixer_interrupt()
1961 ustatus != -ECONNRESET && in scarlett2_mixer_interrupt()
1962 ustatus != -ESHUTDOWN) { in scarlett2_mixer_interrupt()
1963 urb->dev = mixer->chip->dev; in scarlett2_mixer_interrupt()
1970 struct usb_device *dev = mixer->chip->dev; in scarlett2_mixer_status_create()
1975 if (mixer->urb) { in scarlett2_mixer_status_create()
1976 usb_audio_err(mixer->chip, in scarlett2_mixer_status_create()
1982 return -EINVAL; in scarlett2_mixer_status_create()
1984 mixer->urb = usb_alloc_urb(0, GFP_KERNEL); in scarlett2_mixer_status_create()
1985 if (!mixer->urb) in scarlett2_mixer_status_create()
1986 return -ENOMEM; in scarlett2_mixer_status_create()
1990 return -ENOMEM; in scarlett2_mixer_status_create()
1992 usb_fill_int_urb(mixer->urb, dev, pipe, in scarlett2_mixer_status_create()
1997 return usb_submit_urb(mixer->urb, GFP_KERNEL); in scarlett2_mixer_status_create()
2007 if (!mixer->protocol) in snd_scarlett_gen2_controls_create()
2010 switch (mixer->chip->usb_id) { in snd_scarlett_gen2_controls_create()
2021 return -EINVAL; in snd_scarlett_gen2_controls_create()
2024 if (!(mixer->chip->setup & SCARLETT2_ENABLE)) { in snd_scarlett_gen2_controls_create()
2025 usb_audio_err(mixer->chip, in snd_scarlett_gen2_controls_create()
2068 if (info->button_count) { in snd_scarlett_gen2_controls_create()