ALSA: bebob: delayed registration of sound card
Some bebob based units tends to fail asynchronous communication when IEEE 1394 bus is under bus-reset state. When registering sound card instance at unit probe callback, userspace applications can be involved to the state. This commit postpones the registration till the bus is calm. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
923f92ebb4
commit
04a2c73c97
2 changed files with 131 additions and 89 deletions
|
@ -126,6 +126,17 @@ name_device(struct snd_bebob *bebob)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bebob_free(struct snd_bebob *bebob)
|
||||||
|
{
|
||||||
|
snd_bebob_stream_destroy_duplex(bebob);
|
||||||
|
fw_unit_put(bebob->unit);
|
||||||
|
|
||||||
|
kfree(bebob->maudio_special_quirk);
|
||||||
|
|
||||||
|
mutex_destroy(&bebob->mutex);
|
||||||
|
kfree(bebob);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This module releases the FireWire unit data after all ALSA character devices
|
* This module releases the FireWire unit data after all ALSA character devices
|
||||||
* are released by applications. This is for releasing stream data or finishing
|
* are released by applications. This is for releasing stream data or finishing
|
||||||
|
@ -137,18 +148,11 @@ bebob_card_free(struct snd_card *card)
|
||||||
{
|
{
|
||||||
struct snd_bebob *bebob = card->private_data;
|
struct snd_bebob *bebob = card->private_data;
|
||||||
|
|
||||||
snd_bebob_stream_destroy_duplex(bebob);
|
mutex_lock(&devices_mutex);
|
||||||
fw_unit_put(bebob->unit);
|
clear_bit(bebob->card_index, devices_used);
|
||||||
|
mutex_unlock(&devices_mutex);
|
||||||
|
|
||||||
kfree(bebob->maudio_special_quirk);
|
bebob_free(card->private_data);
|
||||||
|
|
||||||
if (bebob->card_index >= 0) {
|
|
||||||
mutex_lock(&devices_mutex);
|
|
||||||
clear_bit(bebob->card_index, devices_used);
|
|
||||||
mutex_unlock(&devices_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_destroy(&bebob->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct snd_bebob_spec *
|
static const struct snd_bebob_spec *
|
||||||
|
@ -176,16 +180,17 @@ check_audiophile_booted(struct fw_unit *unit)
|
||||||
return strncmp(name, "FW Audiophile Bootloader", 15) != 0;
|
return strncmp(name, "FW Audiophile Bootloader", 15) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
bebob_probe(struct fw_unit *unit,
|
do_registration(struct work_struct *work)
|
||||||
const struct ieee1394_device_id *entry)
|
|
||||||
{
|
{
|
||||||
struct snd_card *card;
|
struct snd_bebob *bebob =
|
||||||
struct snd_bebob *bebob;
|
container_of(work, struct snd_bebob, dwork.work);
|
||||||
const struct snd_bebob_spec *spec;
|
|
||||||
unsigned int card_index;
|
unsigned int card_index;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (bebob->registered)
|
||||||
|
return;
|
||||||
|
|
||||||
mutex_lock(&devices_mutex);
|
mutex_lock(&devices_mutex);
|
||||||
|
|
||||||
for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
|
for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
|
||||||
|
@ -193,64 +198,39 @@ bebob_probe(struct fw_unit *unit,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (card_index >= SNDRV_CARDS) {
|
if (card_index >= SNDRV_CARDS) {
|
||||||
err = -ENOENT;
|
mutex_unlock(&devices_mutex);
|
||||||
goto end;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entry->vendor_id == VEN_FOCUSRITE) &&
|
err = snd_card_new(&bebob->unit->device, index[card_index],
|
||||||
(entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH))
|
id[card_index], THIS_MODULE, 0, &bebob->card);
|
||||||
spec = get_saffire_spec(unit);
|
if (err < 0) {
|
||||||
else if ((entry->vendor_id == VEN_MAUDIO1) &&
|
mutex_unlock(&devices_mutex);
|
||||||
(entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH) &&
|
return;
|
||||||
!check_audiophile_booted(unit))
|
|
||||||
spec = NULL;
|
|
||||||
else
|
|
||||||
spec = (const struct snd_bebob_spec *)entry->driver_data;
|
|
||||||
|
|
||||||
if (spec == NULL) {
|
|
||||||
if ((entry->vendor_id == VEN_MAUDIO1) ||
|
|
||||||
(entry->vendor_id == VEN_MAUDIO2))
|
|
||||||
err = snd_bebob_maudio_load_firmware(unit);
|
|
||||||
else
|
|
||||||
err = -ENOSYS;
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_card_new(&unit->device, index[card_index], id[card_index],
|
|
||||||
THIS_MODULE, sizeof(struct snd_bebob), &card);
|
|
||||||
if (err < 0)
|
|
||||||
goto end;
|
|
||||||
bebob = card->private_data;
|
|
||||||
bebob->card_index = card_index;
|
|
||||||
set_bit(card_index, devices_used);
|
|
||||||
card->private_free = bebob_card_free;
|
|
||||||
|
|
||||||
bebob->card = card;
|
|
||||||
bebob->unit = fw_unit_get(unit);
|
|
||||||
bebob->spec = spec;
|
|
||||||
mutex_init(&bebob->mutex);
|
|
||||||
spin_lock_init(&bebob->lock);
|
|
||||||
init_waitqueue_head(&bebob->hwdep_wait);
|
|
||||||
|
|
||||||
err = name_device(bebob);
|
err = name_device(bebob);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((entry->vendor_id == VEN_MAUDIO1) &&
|
if (bebob->spec == &maudio_special_spec) {
|
||||||
(entry->model_id == MODEL_MAUDIO_FW1814))
|
if (bebob->entry->model_id == MODEL_MAUDIO_FW1814)
|
||||||
err = snd_bebob_maudio_special_discover(bebob, true);
|
err = snd_bebob_maudio_special_discover(bebob, true);
|
||||||
else if ((entry->vendor_id == VEN_MAUDIO1) &&
|
else
|
||||||
(entry->model_id == MODEL_MAUDIO_PROJECTMIX))
|
err = snd_bebob_maudio_special_discover(bebob, false);
|
||||||
err = snd_bebob_maudio_special_discover(bebob, false);
|
} else {
|
||||||
else
|
|
||||||
err = snd_bebob_stream_discover(bebob);
|
err = snd_bebob_stream_discover(bebob);
|
||||||
|
}
|
||||||
|
if (err < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
err = snd_bebob_stream_init_duplex(bebob);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
snd_bebob_proc_init(bebob);
|
snd_bebob_proc_init(bebob);
|
||||||
|
|
||||||
if ((bebob->midi_input_ports > 0) ||
|
if (bebob->midi_input_ports > 0 || bebob->midi_output_ports > 0) {
|
||||||
(bebob->midi_output_ports > 0)) {
|
|
||||||
err = snd_bebob_create_midi_devices(bebob);
|
err = snd_bebob_create_midi_devices(bebob);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -264,16 +244,75 @@ bebob_probe(struct fw_unit *unit,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
err = snd_bebob_stream_init_duplex(bebob);
|
err = snd_card_register(bebob->card);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!bebob->maudio_special_quirk) {
|
set_bit(card_index, devices_used);
|
||||||
err = snd_card_register(card);
|
mutex_unlock(&devices_mutex);
|
||||||
if (err < 0) {
|
|
||||||
snd_bebob_stream_destroy_duplex(bebob);
|
/*
|
||||||
goto error;
|
* After registered, bebob instance can be released corresponding to
|
||||||
}
|
* releasing the sound card instance.
|
||||||
|
*/
|
||||||
|
bebob->card->private_free = bebob_card_free;
|
||||||
|
bebob->card->private_data = bebob;
|
||||||
|
bebob->registered = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
error:
|
||||||
|
mutex_unlock(&devices_mutex);
|
||||||
|
snd_bebob_stream_destroy_duplex(bebob);
|
||||||
|
snd_card_free(bebob->card);
|
||||||
|
dev_info(&bebob->unit->device,
|
||||||
|
"Sound card registration failed: %d\n", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
|
||||||
|
{
|
||||||
|
struct snd_bebob *bebob;
|
||||||
|
const struct snd_bebob_spec *spec;
|
||||||
|
|
||||||
|
if (entry->vendor_id == VEN_FOCUSRITE &&
|
||||||
|
entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH)
|
||||||
|
spec = get_saffire_spec(unit);
|
||||||
|
else if (entry->vendor_id == VEN_MAUDIO1 &&
|
||||||
|
entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH &&
|
||||||
|
!check_audiophile_booted(unit))
|
||||||
|
spec = NULL;
|
||||||
|
else
|
||||||
|
spec = (const struct snd_bebob_spec *)entry->driver_data;
|
||||||
|
|
||||||
|
if (spec == NULL) {
|
||||||
|
if (entry->vendor_id == VEN_MAUDIO1 ||
|
||||||
|
entry->vendor_id == VEN_MAUDIO2)
|
||||||
|
return snd_bebob_maudio_load_firmware(unit);
|
||||||
|
else
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate this independent of sound card instance. */
|
||||||
|
bebob = kzalloc(sizeof(struct snd_bebob), GFP_KERNEL);
|
||||||
|
if (bebob == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
bebob->unit = fw_unit_get(unit);
|
||||||
|
bebob->entry = entry;
|
||||||
|
bebob->spec = spec;
|
||||||
|
dev_set_drvdata(&unit->device, bebob);
|
||||||
|
|
||||||
|
mutex_init(&bebob->mutex);
|
||||||
|
spin_lock_init(&bebob->lock);
|
||||||
|
init_waitqueue_head(&bebob->hwdep_wait);
|
||||||
|
|
||||||
|
/* Allocate and register this sound card later. */
|
||||||
|
INIT_DEFERRABLE_WORK(&bebob->dwork, do_registration);
|
||||||
|
|
||||||
|
if (entry->vendor_id != VEN_MAUDIO1 ||
|
||||||
|
(entry->model_id != MODEL_MAUDIO_FW1814 &&
|
||||||
|
entry->model_id != MODEL_MAUDIO_PROJECTMIX)) {
|
||||||
|
snd_fw_schedule_registration(unit, &bebob->dwork);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* This is a workaround. This bus reset seems to have an effect
|
* This is a workaround. This bus reset seems to have an effect
|
||||||
|
@ -285,19 +324,11 @@ bebob_probe(struct fw_unit *unit,
|
||||||
* signals from dbus and starts I/Os. To avoid I/Os till the
|
* signals from dbus and starts I/Os. To avoid I/Os till the
|
||||||
* future bus reset, registration is done in next update().
|
* future bus reset, registration is done in next update().
|
||||||
*/
|
*/
|
||||||
bebob->deferred_registration = true;
|
|
||||||
fw_schedule_bus_reset(fw_parent_device(bebob->unit)->card,
|
fw_schedule_bus_reset(fw_parent_device(bebob->unit)->card,
|
||||||
false, true);
|
false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_set_drvdata(&unit->device, bebob);
|
return 0;
|
||||||
end:
|
|
||||||
mutex_unlock(&devices_mutex);
|
|
||||||
return err;
|
|
||||||
error:
|
|
||||||
mutex_unlock(&devices_mutex);
|
|
||||||
snd_card_free(card);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -324,15 +355,11 @@ bebob_update(struct fw_unit *unit)
|
||||||
if (bebob == NULL)
|
if (bebob == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fcp_bus_reset(bebob->unit);
|
/* Postpone a workqueue for deferred registration. */
|
||||||
|
if (!bebob->registered)
|
||||||
if (bebob->deferred_registration) {
|
snd_fw_schedule_registration(unit, &bebob->dwork);
|
||||||
if (snd_card_register(bebob->card) < 0) {
|
else
|
||||||
snd_bebob_stream_destroy_duplex(bebob);
|
fcp_bus_reset(bebob->unit);
|
||||||
snd_card_free(bebob->card);
|
|
||||||
}
|
|
||||||
bebob->deferred_registration = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bebob_remove(struct fw_unit *unit)
|
static void bebob_remove(struct fw_unit *unit)
|
||||||
|
@ -342,8 +369,20 @@ static void bebob_remove(struct fw_unit *unit)
|
||||||
if (bebob == NULL)
|
if (bebob == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* No need to wait for releasing card object in this context. */
|
/*
|
||||||
snd_card_free_when_closed(bebob->card);
|
* Confirm to stop the work for registration before the sound card is
|
||||||
|
* going to be released. The work is not scheduled again because bus
|
||||||
|
* reset handler is not called anymore.
|
||||||
|
*/
|
||||||
|
cancel_delayed_work_sync(&bebob->dwork);
|
||||||
|
|
||||||
|
if (bebob->registered) {
|
||||||
|
/* No need to wait for releasing card object in this context. */
|
||||||
|
snd_card_free_when_closed(bebob->card);
|
||||||
|
} else {
|
||||||
|
/* Don't forget this case. */
|
||||||
|
bebob_free(bebob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct snd_bebob_rate_spec normal_rate_spec = {
|
static const struct snd_bebob_rate_spec normal_rate_spec = {
|
||||||
|
|
|
@ -83,6 +83,10 @@ struct snd_bebob {
|
||||||
struct mutex mutex;
|
struct mutex mutex;
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
|
|
||||||
|
bool registered;
|
||||||
|
struct delayed_work dwork;
|
||||||
|
|
||||||
|
const struct ieee1394_device_id *entry;
|
||||||
const struct snd_bebob_spec *spec;
|
const struct snd_bebob_spec *spec;
|
||||||
|
|
||||||
unsigned int midi_input_ports;
|
unsigned int midi_input_ports;
|
||||||
|
@ -111,7 +115,6 @@ struct snd_bebob {
|
||||||
|
|
||||||
/* for M-Audio special devices */
|
/* for M-Audio special devices */
|
||||||
void *maudio_special_quirk;
|
void *maudio_special_quirk;
|
||||||
bool deferred_registration;
|
|
||||||
|
|
||||||
/* For BeBoB version quirk. */
|
/* For BeBoB version quirk. */
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
|
|
Loading…
Reference in a new issue