Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Linux driver for TerraTec DMX 6Fire USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Main routines and module definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author:	Torsten Schenk <torsten.schenk@zoho.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Created:	Jan 01, 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright:	(C) Torsten Schenk
^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) #include "chip.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "firmware.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "pcm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "control.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "comm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "midi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Torsten Schenk <torsten.schenk@zoho.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_DESCRIPTION("TerraTec DMX 6Fire USB audio driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_SUPPORTED_DEVICE("{{TerraTec,DMX 6Fire USB}}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static struct sfire_chip *chips[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static struct usb_device *devices[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) MODULE_PARM_DESC(index, "Index value for the 6fire sound device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) module_param_array(id, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) MODULE_PARM_DESC(id, "ID string for the 6fire sound device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) MODULE_PARM_DESC(enable, "Enable the 6fire sound device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static DEFINE_MUTEX(register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static void usb6fire_chip_abort(struct sfire_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		if (chip->pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			usb6fire_pcm_abort(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (chip->midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			usb6fire_midi_abort(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (chip->comm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			usb6fire_comm_abort(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		if (chip->control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			usb6fire_control_abort(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (chip->card) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			snd_card_disconnect(chip->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			snd_card_free_when_closed(chip->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			chip->card = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void usb6fire_chip_destroy(struct sfire_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		if (chip->pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			usb6fire_pcm_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (chip->midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			usb6fire_midi_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (chip->comm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			usb6fire_comm_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (chip->control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			usb6fire_control_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (chip->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			snd_card_free(chip->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int usb6fire_chip_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			       const struct usb_device_id *usb_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct sfire_chip *chip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct usb_device *device = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int regidx = -1; /* index in module parameter array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct snd_card *card = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/* look if we already serve this card and return if so */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	mutex_lock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	for (i = 0; i < SNDRV_CARDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (devices[i] == device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			if (chips[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				chips[i]->intf_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			usb_set_intfdata(intf, chips[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			mutex_unlock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		} else if (!devices[i] && regidx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			regidx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (regidx < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		mutex_unlock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dev_err(&intf->dev, "too many cards registered.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	devices[regidx] = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	mutex_unlock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/* check, if firmware is present on device, upload it if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ret = usb6fire_fw_init(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	else if (ret == FW_NOT_READY) /* firmware update performed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* if we are here, card can be registered in alsa. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (usb_set_interface(device, 0, 0) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		dev_err(&intf->dev, "can't set first interface.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	ret = snd_card_new(&intf->dev, index[regidx], id[regidx],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			   THIS_MODULE, sizeof(struct sfire_chip), &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dev_err(&intf->dev, "cannot create alsa card.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	strcpy(card->driver, "6FireUSB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	strcpy(card->shortname, "TerraTec DMX6FireUSB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	sprintf(card->longname, "%s at %d:%d", card->shortname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			device->bus->busnum, device->devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	chip = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	chips[regidx] = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	chip->dev = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	chip->regidx = regidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	chip->intf_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	chip->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = usb6fire_comm_init(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		goto destroy_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ret = usb6fire_midi_init(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		goto destroy_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	ret = usb6fire_pcm_init(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		goto destroy_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	ret = usb6fire_control_init(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		goto destroy_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	ret = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		dev_err(&intf->dev, "cannot register card.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		goto destroy_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	usb_set_intfdata(intf, chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) destroy_chip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	usb6fire_chip_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void usb6fire_chip_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct sfire_chip *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	chip = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (chip) { /* if !chip, fw upload has been performed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		chip->intf_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (!chip->intf_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			mutex_lock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			devices[chip->regidx] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			chips[chip->regidx] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			mutex_unlock(&register_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			chip->shutdown = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			usb6fire_chip_abort(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			usb6fire_chip_destroy(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static const struct usb_device_id device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		.idVendor = 0x0ccd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		.idProduct = 0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_DEVICE_TABLE(usb, device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static struct usb_driver usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.name = "snd-usb-6fire",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.probe = usb6fire_chip_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.disconnect = usb6fire_chip_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	.id_table = device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) module_usb_driver(usb_driver);