ALSA: firewire-lib: add new function to schedule a work for sound card registration
[cascardo/linux.git] / sound / firewire / dice / dice.c
index 53ca441..96fe68f 100644 (file)
@@ -20,8 +20,6 @@ MODULE_LICENSE("GPL v2");
 #define WEISS_CATEGORY_ID      0x00
 #define LOUD_CATEGORY_ID       0x10
 
-#define PROBE_DELAY_MS         (2 * MSEC_PER_SEC)
-
 /*
  * Some models support several isochronous channels, while these streams are not
  * always available. In this case, add the model name to this list.
@@ -235,27 +233,12 @@ static void do_registration(struct work_struct *work)
 error:
        snd_dice_stream_destroy_duplex(dice);
        snd_dice_transaction_destroy(dice);
+       snd_dice_stream_destroy_duplex(dice);
        snd_card_free(dice->card);
        dev_info(&dice->unit->device,
                 "Sound card registration failed: %d\n", err);
 }
 
-static void schedule_registration(struct snd_dice *dice)
-{
-       struct fw_card *fw_card = fw_parent_device(dice->unit)->card;
-       u64 now, delay;
-
-       now = get_jiffies_64();
-       delay = fw_card->reset_jiffies + msecs_to_jiffies(PROBE_DELAY_MS);
-
-       if (time_after64(delay, now))
-               delay -= now;
-       else
-               delay = 0;
-
-       mod_delayed_work(system_wq, &dice->dwork, delay);
-}
-
 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
 {
        struct snd_dice *dice;
@@ -280,7 +263,7 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
 
        /* Allocate and register this sound card later. */
        INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
-       schedule_registration(dice);
+       snd_fw_schedule_registration(unit, &dice->dwork);
 
        return 0;
 }
@@ -311,7 +294,7 @@ static void dice_bus_reset(struct fw_unit *unit)
 
        /* Postpone a workqueue for deferred registration. */
        if (!dice->registered)
-               schedule_registration(dice);
+               snd_fw_schedule_registration(unit, &dice->dwork);
 
        /* The handler address register becomes initialized. */
        snd_dice_transaction_reinit(dice);