Skip to content

Commit

Permalink
Simplify the probing scheme to be per-device instead of per-interface
Browse files Browse the repository at this point in the history
The hiFace devices only have one USB interface per device, so there is
no need to check if the device was already registered with another
interface.

This allows to simplify the probing scheme. As a consequence the
"intf_count" and "shutdown" fields of hiface_chip can be dropped.

Signed-off-by: Antonio Ospite <ao2@amarulasolutions.com>
  • Loading branch information
ao2 committed Jun 3, 2013
1 parent 747bbc6 commit 11329c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 50 deletions.
67 changes: 20 additions & 47 deletions chip.c
Expand Up @@ -57,8 +57,6 @@ MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");

static struct hiface_chip *chips[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;

static DEFINE_MUTEX(register_mutex);

struct hiface_vendor_quirk {
Expand Down Expand Up @@ -124,38 +122,23 @@ static int hiface_chip_probe(struct usb_interface *intf,
/* check whether the card is already registered */
chip = NULL;
mutex_lock(&register_mutex);
for (i = 0; i < SNDRV_CARDS; i++) {
if (chips[i] && chips[i]->dev == device) {
if (chips[i]->shutdown) {
dev_err(&device->dev, CARD_NAME " device is in the shutdown state, cannot create a card instance\n");
ret = -ENODEV;
goto err;
}
chip = chips[i];

for (i = 0; i < SNDRV_CARDS; i++)
if (enable[i])
break;
}
}
if (!chip) {
/* it's a fresh one.
* now look for an empty slot and create a new card instance
*/
for (i = 0; i < SNDRV_CARDS; i++)
if (enable[i] && !chips[i]) {
ret = hiface_chip_create(device, i, quirk,
&chip);
if (ret < 0)
goto err;

snd_card_set_dev(chip->card, &intf->dev);
break;
}
if (!chip) {
dev_err(&device->dev, "no available " CARD_NAME " audio device\n");
ret = -ENODEV;
goto err;
}

if (i >= SNDRV_CARDS) {
dev_err(&device->dev, "no available " CARD_NAME " audio device\n");
ret = -ENODEV;
goto err;
}

ret = hiface_chip_create(device, i, quirk, &chip);
if (ret < 0)
goto err;

snd_card_set_dev(chip->card, &intf->dev);

ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0);
if (ret < 0)
goto err_chip_destroy;
Expand All @@ -166,9 +149,6 @@ static int hiface_chip_probe(struct usb_interface *intf,
goto err_chip_destroy;
}

chips[chip->index] = chip;
chip->intf_count++;

mutex_unlock(&register_mutex);

usb_set_intfdata(intf, chip);
Expand All @@ -191,19 +171,12 @@ static void hiface_chip_disconnect(struct usb_interface *intf)
return;

card = chip->card;
chip->intf_count--;
if (chip->intf_count <= 0) {
/* Make sure that the userspace cannot create new request */
snd_card_disconnect(card);

mutex_lock(&register_mutex);
chips[chip->index] = NULL;
mutex_unlock(&register_mutex);

chip->shutdown = true;
hiface_pcm_abort(chip);
snd_card_free_when_closed(card);
}

/* Make sure that the userspace cannot create new request */
snd_card_disconnect(card);

hiface_pcm_abort(chip);
snd_card_free_when_closed(card);
}

static const struct usb_device_id device_table[] = {
Expand Down
3 changes: 0 additions & 3 deletions chip.h
Expand Up @@ -25,10 +25,7 @@ struct pcm_runtime;
struct hiface_chip {
struct usb_device *dev;
struct snd_card *card;
int intf_count; /* number of registered interfaces */
int index; /* index in module parameter arrays */
bool shutdown;

struct pcm_runtime *pcm;
};
#endif /* HIFACE_CHIP_H */

0 comments on commit 11329c9

Please sign in to comment.