Linux 6.9-rc5
[sfrench/cifs-2.6.git] / sound / firewire / oxfw / oxfw.c
index 1f1e3236efb8e045300d4cc074f95bda46fd6a8c..98ae0e8cba8790eead0a6fb0c3a102bb590cd13d 100644 (file)
 #define VENDOR_TASCAM          0x00022e
 #define OUI_STANTON            0x001260
 #define OUI_APOGEE             0x0003db
+#define OUI_OXFORD             0x0030e0
 
 #define MODEL_SATELLITE                0x00200f
+#define MODEL_SCS1M            0x001000
+#define MODEL_DUET_FW          0x01dddd
+#define MODEL_ONYX_1640I       0x001640
 
 #define SPECIFIER_1394TA       0x00a02d
 #define VERSION_AVC            0x010001
 
 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
 MODULE_ALIAS("snd-firewire-speakers");
 MODULE_ALIAS("snd-scs1x");
 
@@ -41,13 +45,11 @@ struct compat_info {
 
 static bool detect_loud_models(struct fw_unit *unit)
 {
-       const char *const models[] = {
+       static const char *const models[] = {
                "Onyxi",
                "Onyx-i",
                "Onyx 1640i",
                "d.Pro",
-               "Mackie Onyx Satellite",
-               "Tapco LINK.firewire 4x6",
                "U.420"};
        char model[32];
        int err;
@@ -60,7 +62,7 @@ static bool detect_loud_models(struct fw_unit *unit)
        return match_string(models, ARRAY_SIZE(models), model) >= 0;
 }
 
-static int name_card(struct snd_oxfw *oxfw)
+static int name_card(struct snd_oxfw *oxfw, const struct ieee1394_device_id *entry)
 {
        struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
        const struct compat_info *info;
@@ -88,10 +90,12 @@ static int name_card(struct snd_oxfw *oxfw)
                goto end;
        be32_to_cpus(&firmware);
 
+       if (firmware >> 20 == 0x970)
+               oxfw->quirks |= SND_OXFW_QUIRK_JUMBO_PAYLOAD;
+
        /* to apply card definitions */
-       if (oxfw->entry->vendor_id == VENDOR_GRIFFIN ||
-           oxfw->entry->vendor_id == VENDOR_LACIE) {
-               info = (const struct compat_info *)oxfw->entry->driver_data;
+       if (entry->vendor_id == VENDOR_GRIFFIN || entry->vendor_id == VENDOR_LACIE) {
+               info = (const struct compat_info *)entry->driver_data;
                d = info->driver_name;
                v = info->vendor_name;
                m = info->model_name;
@@ -105,11 +109,11 @@ static int name_card(struct snd_oxfw *oxfw)
        strcpy(oxfw->card->mixername, m);
        strcpy(oxfw->card->shortname, m);
 
-       snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
-                "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
-                v, m, firmware >> 20, firmware & 0xffff,
-                fw_dev->config_rom[3], fw_dev->config_rom[4],
-                dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
+       scnprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
+                 "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
+                 v, m, firmware >> 20, firmware & 0xffff,
+                 fw_dev->config_rom[3], fw_dev->config_rom[4],
+                 dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
 end:
        return err;
 }
@@ -120,9 +124,12 @@ static void oxfw_card_free(struct snd_card *card)
 
        if (oxfw->has_output || oxfw->has_input)
                snd_oxfw_stream_destroy_duplex(oxfw);
+
+       mutex_destroy(&oxfw->mutex);
+       fw_unit_put(oxfw->unit);
 }
 
-static int detect_quirks(struct snd_oxfw *oxfw)
+static int detect_quirks(struct snd_oxfw *oxfw, const struct ieee1394_device_id *entry)
 {
        struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
        struct fw_csr_iterator it;
@@ -133,28 +140,37 @@ static int detect_quirks(struct snd_oxfw *oxfw)
         * Add ALSA control elements for two models to keep compatibility to
         * old firewire-speaker module.
         */
-       if (oxfw->entry->vendor_id == VENDOR_GRIFFIN)
+       if (entry->vendor_id == VENDOR_GRIFFIN)
                return snd_oxfw_add_spkr(oxfw, false);
-       if (oxfw->entry->vendor_id == VENDOR_LACIE)
+       if (entry->vendor_id == VENDOR_LACIE)
                return snd_oxfw_add_spkr(oxfw, true);
 
        /*
         * Stanton models supports asynchronous transactions for unique MIDI
         * messages.
         */
-       if (oxfw->entry->vendor_id == OUI_STANTON) {
-               /* No physical MIDI ports. */
+       if (entry->vendor_id == OUI_STANTON) {
+               oxfw->quirks |= SND_OXFW_QUIRK_SCS_TRANSACTION;
+               if (entry->model_id == MODEL_SCS1M)
+                       oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION;
+
+               // No physical MIDI ports.
                oxfw->midi_input_ports = 0;
                oxfw->midi_output_ports = 0;
 
                return snd_oxfw_scs1x_add(oxfw);
        }
 
+       if (entry->vendor_id == OUI_APOGEE && entry->model_id == MODEL_DUET_FW) {
+               oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION |
+                               SND_OXFW_QUIRK_IGNORE_NO_INFO_PACKET;
+       }
+
        /*
         * TASCAM FireOne has physical control and requires a pair of additional
         * MIDI ports.
         */
-       if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
+       if (entry->vendor_id == VENDOR_TASCAM) {
                oxfw->midi_input_ports++;
                oxfw->midi_output_ports++;
                return 0;
@@ -170,40 +186,63 @@ static int detect_quirks(struct snd_oxfw *oxfw)
                        model = val;
        }
 
-       /*
-        * Mackie Onyx Satellite with base station has a quirk to report a wrong
-        * value in 'dbs' field of CIP header against its format information.
-        */
-       if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
-               oxfw->wrong_dbs = true;
+       if (vendor == VENDOR_LOUD) {
+               // Mackie Onyx Satellite with base station has a quirk to report a wrong
+               // value in 'dbs' field of CIP header against its format information.
+               oxfw->quirks |= SND_OXFW_QUIRK_WRONG_DBS;
+
+               // OXFW971-based models may transfer events by blocking method.
+               if (!(oxfw->quirks & SND_OXFW_QUIRK_JUMBO_PAYLOAD))
+                       oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION;
+
+               if (model == MODEL_ONYX_1640I) {
+                       //Unless receiving packets without NOINFO packet, the device transfers
+                       //mostly half of events in packets than expected.
+                       oxfw->quirks |= SND_OXFW_QUIRK_IGNORE_NO_INFO_PACKET |
+                                       SND_OXFW_QUIRK_VOLUNTARY_RECOVERY;
+               }
+       }
 
        return 0;
 }
 
-static void do_registration(struct work_struct *work)
+static int oxfw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
 {
-       struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work);
+       struct snd_card *card;
+       struct snd_oxfw *oxfw;
        int err;
 
-       if (oxfw->registered)
-               return;
+       if (entry->vendor_id == VENDOR_LOUD && entry->model_id == 0 && !detect_loud_models(unit))
+               return -ENODEV;
 
-       err = snd_card_new(&oxfw->unit->device, -1, NULL, THIS_MODULE, 0,
-                          &oxfw->card);
+       err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*oxfw), &card);
        if (err < 0)
-               return;
-       oxfw->card->private_free = oxfw_card_free;
-       oxfw->card->private_data = oxfw;
+               return err;
+       card->private_free = oxfw_card_free;
+
+       oxfw = card->private_data;
+       oxfw->unit = fw_unit_get(unit);
+       dev_set_drvdata(&unit->device, oxfw);
+       oxfw->card = card;
+
+       mutex_init(&oxfw->mutex);
+       spin_lock_init(&oxfw->lock);
+       init_waitqueue_head(&oxfw->hwdep_wait);
 
-       err = name_card(oxfw);
+       err = name_card(oxfw, entry);
        if (err < 0)
                goto error;
 
+       if (entry->vendor_id == OUI_OXFORD && entry->model_id == 0x00f970) {
+               oxfw->quirks |= SND_OXFW_QUIRK_STREAM_FORMAT_INFO_UNSUPPORTED |
+                               SND_OXFW_QUIRK_DBC_IS_TOTAL_PAYLOAD_QUADLETS;
+       }
+
        err = snd_oxfw_stream_discover(oxfw);
        if (err < 0)
                goto error;
 
-       err = detect_quirks(oxfw);
+       err = detect_quirks(oxfw, entry);
        if (err < 0)
                goto error;
 
@@ -227,85 +266,38 @@ static void do_registration(struct work_struct *work)
                        goto error;
        }
 
-       err = snd_card_register(oxfw->card);
+       err = snd_card_register(card);
        if (err < 0)
                goto error;
 
-       oxfw->registered = true;
-
-       return;
-error:
-       snd_card_free(oxfw->card);
-       dev_info(&oxfw->unit->device,
-                "Sound card registration failed: %d\n", err);
-}
-
-static int oxfw_probe(struct fw_unit *unit,
-                     const struct ieee1394_device_id *entry)
-{
-       struct snd_oxfw *oxfw;
-
-       if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit))
-               return -ENODEV;
-
-       /* Allocate this independent of sound card instance. */
-       oxfw = devm_kzalloc(&unit->device, sizeof(struct snd_oxfw), GFP_KERNEL);
-       if (!oxfw)
-               return -ENOMEM;
-       oxfw->unit = fw_unit_get(unit);
-       dev_set_drvdata(&unit->device, oxfw);
-
-       oxfw->entry = entry;
-       mutex_init(&oxfw->mutex);
-       spin_lock_init(&oxfw->lock);
-       init_waitqueue_head(&oxfw->hwdep_wait);
-
-       /* Allocate and register this sound card later. */
-       INIT_DEFERRABLE_WORK(&oxfw->dwork, do_registration);
-       snd_fw_schedule_registration(unit, &oxfw->dwork);
-
        return 0;
+error:
+       snd_card_free(card);
+       return err;
 }
 
 static void oxfw_bus_reset(struct fw_unit *unit)
 {
        struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
 
-       if (!oxfw->registered)
-               snd_fw_schedule_registration(unit, &oxfw->dwork);
-
        fcp_bus_reset(oxfw->unit);
 
-       if (oxfw->registered) {
-               if (oxfw->has_output || oxfw->has_input) {
-                       mutex_lock(&oxfw->mutex);
-                       snd_oxfw_stream_update_duplex(oxfw);
-                       mutex_unlock(&oxfw->mutex);
-               }
-
-               if (oxfw->entry->vendor_id == OUI_STANTON)
-                       snd_oxfw_scs1x_update(oxfw);
+       if (oxfw->has_output || oxfw->has_input) {
+               mutex_lock(&oxfw->mutex);
+               snd_oxfw_stream_update_duplex(oxfw);
+               mutex_unlock(&oxfw->mutex);
        }
+
+       if (oxfw->quirks & SND_OXFW_QUIRK_SCS_TRANSACTION)
+               snd_oxfw_scs1x_update(oxfw);
 }
 
 static void oxfw_remove(struct fw_unit *unit)
 {
        struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
 
-       /*
-        * 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(&oxfw->dwork);
-
-       if (oxfw->registered) {
-               // Block till all of ALSA character devices are released.
-               snd_card_free(oxfw->card);
-       }
-
-       mutex_destroy(&oxfw->mutex);
-       fw_unit_put(oxfw->unit);
+       // Block till all of ALSA character devices are released.
+       snd_card_free(oxfw->card);
 }
 
 static const struct compat_info griffin_firewave = {
@@ -320,82 +312,69 @@ static const struct compat_info lacie_speakers = {
        .model_name = "FireWire Speakers",
 };
 
+#define OXFW_DEV_ENTRY(vendor, model, data) \
+{ \
+       .match_flags  = IEEE1394_MATCH_VENDOR_ID | \
+                       IEEE1394_MATCH_MODEL_ID | \
+                       IEEE1394_MATCH_SPECIFIER_ID | \
+                       IEEE1394_MATCH_VERSION, \
+       .vendor_id    = vendor, \
+       .model_id     = model, \
+       .specifier_id = SPECIFIER_1394TA, \
+       .version      = VERSION_AVC, \
+       .driver_data  = (kernel_ulong_t)data, \
+}
+
 static const struct ieee1394_device_id oxfw_id_table[] = {
-       {
-               .match_flags  = IEEE1394_MATCH_VENDOR_ID |
-                               IEEE1394_MATCH_MODEL_ID |
-                               IEEE1394_MATCH_SPECIFIER_ID |
-                               IEEE1394_MATCH_VERSION,
-               .vendor_id    = VENDOR_GRIFFIN,
-               .model_id     = 0x00f970,
-               .specifier_id = SPECIFIER_1394TA,
-               .version      = VERSION_AVC,
-               .driver_data  = (kernel_ulong_t)&griffin_firewave,
-       },
-       {
-               .match_flags  = IEEE1394_MATCH_VENDOR_ID |
-                               IEEE1394_MATCH_MODEL_ID |
-                               IEEE1394_MATCH_SPECIFIER_ID |
-                               IEEE1394_MATCH_VERSION,
-               .vendor_id    = VENDOR_LACIE,
-               .model_id     = 0x00f970,
-               .specifier_id = SPECIFIER_1394TA,
-               .version      = VERSION_AVC,
-               .driver_data  = (kernel_ulong_t)&lacie_speakers,
-       },
-       /* Behringer,F-Control Audio 202 */
-       {
-               .match_flags    = IEEE1394_MATCH_VENDOR_ID |
-                                 IEEE1394_MATCH_MODEL_ID,
-               .vendor_id      = VENDOR_BEHRINGER,
-               .model_id       = 0x00fc22,
-       },
-       /*
-        * Any Mackie(Loud) models (name string/model id):
-        *  Onyx-i series (former models):      0x081216
-        *  Mackie Onyx Satellite:              0x00200f
-        *  Tapco LINK.firewire 4x6:            0x000460
-        *  d.2 pro:                            Unknown
-        *  d.4 pro:                            Unknown
-        *  U.420:                              Unknown
-        *  U.420d:                             Unknown
-        */
+       //
+       // OXFW970 devices:
+       // Initial firmware has a quirk to postpone isoc packet transmission during finishing async
+       // transaction. As a result, several isochronous cycles are skipped to transfer the packets
+       // and the audio data frames which should have been transferred during the cycles are put
+       // into packet at the first isoc cycle after the postpone. Furthermore, the value of SYT
+       // field in CIP header is not reliable as synchronization timing,
+       //
+       OXFW_DEV_ENTRY(VENDOR_GRIFFIN, 0x00f970, &griffin_firewave),
+       OXFW_DEV_ENTRY(VENDOR_LACIE, 0x00f970, &lacie_speakers),
+       // Miglia HarmonyAudio (HA02). The numeric vendor ID is ASIC vendor and the model ID is the
+       // default value of ASIC.
+       OXFW_DEV_ENTRY(OUI_OXFORD, 0x00f970, NULL),
+       // Behringer,F-Control Audio 202. The value of SYT field is not reliable at all.
+       OXFW_DEV_ENTRY(VENDOR_BEHRINGER, 0x00fc22, NULL),
+       // Loud Technologies, Tapco Link.FireWire 4x6. The value of SYT field is always 0xffff.
+       OXFW_DEV_ENTRY(VENDOR_LOUD, 0x000460, NULL),
+       // Loud Technologies, Mackie Onyx Satellite. Although revised version of firmware is
+       // installed to avoid the postpone, the value of SYT field is always 0xffff.
+       OXFW_DEV_ENTRY(VENDOR_LOUD, MODEL_SATELLITE, NULL),
+
+       //
+       // OXFW971 devices:
+       // The value of SYT field in CIP header is enough reliable. Both of blocking and non-blocking
+       // transmission methods are available.
+       //
+       // Any Mackie(Loud) models (name string/model id):
+       //  Onyx-i series (former models):      0x081216
+       //  Onyx 1640i:                         0x001640
+       //  d.2 pro/d.4 pro (built-in card):    Unknown
+       //  U.420:                              Unknown
+       //  U.420d:                             Unknown
        {
                .match_flags    = IEEE1394_MATCH_VENDOR_ID |
                                  IEEE1394_MATCH_SPECIFIER_ID |
                                  IEEE1394_MATCH_VERSION,
                .vendor_id      = VENDOR_LOUD,
+               .model_id       = 0,
                .specifier_id   = SPECIFIER_1394TA,
                .version        = VERSION_AVC,
        },
-       /* TASCAM, FireOne */
-       {
-               .match_flags    = IEEE1394_MATCH_VENDOR_ID |
-                                 IEEE1394_MATCH_MODEL_ID,
-               .vendor_id      = VENDOR_TASCAM,
-               .model_id       = 0x800007,
-       },
-       /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
-       {
-               .match_flags    = IEEE1394_MATCH_VENDOR_ID |
-                                 IEEE1394_MATCH_MODEL_ID,
-               .vendor_id      = OUI_STANTON,
-               .model_id       = 0x001000,
-       },
-       /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
-       {
-               .match_flags    = IEEE1394_MATCH_VENDOR_ID |
-                                 IEEE1394_MATCH_MODEL_ID,
-               .vendor_id      = OUI_STANTON,
-               .model_id       = 0x002000,
-       },
-       // APOGEE, duet FireWire
-       {
-               .match_flags    = IEEE1394_MATCH_VENDOR_ID |
-                                 IEEE1394_MATCH_MODEL_ID,
-               .vendor_id      = OUI_APOGEE,
-               .model_id       = 0x01dddd,
-       },
+       // TASCAM, FireOne.
+       OXFW_DEV_ENTRY(VENDOR_TASCAM, 0x800007, NULL),
+       // Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m).
+       OXFW_DEV_ENTRY(OUI_STANTON, MODEL_SCS1M, NULL),
+       // Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d).
+       OXFW_DEV_ENTRY(OUI_STANTON, 0x002000, NULL),
+       // APOGEE, duet FireWire.
+       OXFW_DEV_ENTRY(OUI_APOGEE, MODEL_DUET_FW, NULL),
        { }
 };
 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);