Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * oxfw.c - a part of driver for OXFW970/971 based devices
0004  *
0005  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
0006  */
0007 
0008 #include "oxfw.h"
0009 
0010 #define OXFORD_FIRMWARE_ID_ADDRESS  (CSR_REGISTER_BASE + 0x50000)
0011 /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
0012 
0013 #define OXFORD_HARDWARE_ID_ADDRESS  (CSR_REGISTER_BASE + 0x90020)
0014 #define OXFORD_HARDWARE_ID_OXFW970  0x39443841
0015 #define OXFORD_HARDWARE_ID_OXFW971  0x39373100
0016 
0017 #define VENDOR_LOUD     0x000ff2
0018 #define VENDOR_GRIFFIN      0x001292
0019 #define VENDOR_BEHRINGER    0x001564
0020 #define VENDOR_LACIE        0x00d04b
0021 #define VENDOR_TASCAM       0x00022e
0022 #define OUI_STANTON     0x001260
0023 #define OUI_APOGEE      0x0003db
0024 
0025 #define MODEL_SATELLITE     0x00200f
0026 #define MODEL_SCS1M     0x001000
0027 #define MODEL_DUET_FW       0x01dddd
0028 #define MODEL_ONYX_1640I    0x001640
0029 
0030 #define SPECIFIER_1394TA    0x00a02d
0031 #define VERSION_AVC     0x010001
0032 
0033 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
0034 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
0035 MODULE_LICENSE("GPL v2");
0036 MODULE_ALIAS("snd-firewire-speakers");
0037 MODULE_ALIAS("snd-scs1x");
0038 
0039 struct compat_info {
0040     const char *driver_name;
0041     const char *vendor_name;
0042     const char *model_name;
0043 };
0044 
0045 static bool detect_loud_models(struct fw_unit *unit)
0046 {
0047     const char *const models[] = {
0048         "Onyxi",
0049         "Onyx-i",
0050         "Onyx 1640i",
0051         "d.Pro",
0052         "U.420"};
0053     char model[32];
0054     int err;
0055 
0056     err = fw_csr_string(unit->directory, CSR_MODEL,
0057                 model, sizeof(model));
0058     if (err < 0)
0059         return false;
0060 
0061     return match_string(models, ARRAY_SIZE(models), model) >= 0;
0062 }
0063 
0064 static int name_card(struct snd_oxfw *oxfw, const struct ieee1394_device_id *entry)
0065 {
0066     struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
0067     const struct compat_info *info;
0068     char vendor[24];
0069     char model[32];
0070     const char *d, *v, *m;
0071     u32 firmware;
0072     int err;
0073 
0074     /* get vendor name from root directory */
0075     err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
0076                 vendor, sizeof(vendor));
0077     if (err < 0)
0078         goto end;
0079 
0080     /* get model name from unit directory */
0081     err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
0082                 model, sizeof(model));
0083     if (err < 0)
0084         goto end;
0085 
0086     err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
0087                  OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
0088     if (err < 0)
0089         goto end;
0090     be32_to_cpus(&firmware);
0091 
0092     if (firmware >> 20 == 0x970)
0093         oxfw->quirks |= SND_OXFW_QUIRK_JUMBO_PAYLOAD;
0094 
0095     /* to apply card definitions */
0096     if (entry->vendor_id == VENDOR_GRIFFIN || entry->vendor_id == VENDOR_LACIE) {
0097         info = (const struct compat_info *)entry->driver_data;
0098         d = info->driver_name;
0099         v = info->vendor_name;
0100         m = info->model_name;
0101     } else {
0102         d = "OXFW";
0103         v = vendor;
0104         m = model;
0105     }
0106 
0107     strcpy(oxfw->card->driver, d);
0108     strcpy(oxfw->card->mixername, m);
0109     strcpy(oxfw->card->shortname, m);
0110 
0111     snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
0112          "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
0113          v, m, firmware >> 20, firmware & 0xffff,
0114          fw_dev->config_rom[3], fw_dev->config_rom[4],
0115          dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
0116 end:
0117     return err;
0118 }
0119 
0120 static void oxfw_card_free(struct snd_card *card)
0121 {
0122     struct snd_oxfw *oxfw = card->private_data;
0123 
0124     if (oxfw->has_output || oxfw->has_input)
0125         snd_oxfw_stream_destroy_duplex(oxfw);
0126 
0127     mutex_destroy(&oxfw->mutex);
0128     fw_unit_put(oxfw->unit);
0129 }
0130 
0131 static int detect_quirks(struct snd_oxfw *oxfw, const struct ieee1394_device_id *entry)
0132 {
0133     struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
0134     struct fw_csr_iterator it;
0135     int key, val;
0136     int vendor, model;
0137 
0138     /*
0139      * Add ALSA control elements for two models to keep compatibility to
0140      * old firewire-speaker module.
0141      */
0142     if (entry->vendor_id == VENDOR_GRIFFIN)
0143         return snd_oxfw_add_spkr(oxfw, false);
0144     if (entry->vendor_id == VENDOR_LACIE)
0145         return snd_oxfw_add_spkr(oxfw, true);
0146 
0147     /*
0148      * Stanton models supports asynchronous transactions for unique MIDI
0149      * messages.
0150      */
0151     if (entry->vendor_id == OUI_STANTON) {
0152         oxfw->quirks |= SND_OXFW_QUIRK_SCS_TRANSACTION;
0153         if (entry->model_id == MODEL_SCS1M)
0154             oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION;
0155 
0156         // No physical MIDI ports.
0157         oxfw->midi_input_ports = 0;
0158         oxfw->midi_output_ports = 0;
0159 
0160         return snd_oxfw_scs1x_add(oxfw);
0161     }
0162 
0163     if (entry->vendor_id == OUI_APOGEE && entry->model_id == MODEL_DUET_FW) {
0164         oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION |
0165                 SND_OXFW_QUIRK_IGNORE_NO_INFO_PACKET;
0166     }
0167 
0168     /*
0169      * TASCAM FireOne has physical control and requires a pair of additional
0170      * MIDI ports.
0171      */
0172     if (entry->vendor_id == VENDOR_TASCAM) {
0173         oxfw->midi_input_ports++;
0174         oxfw->midi_output_ports++;
0175         return 0;
0176     }
0177 
0178     /* Seek from Root Directory of Config ROM. */
0179     vendor = model = 0;
0180     fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
0181     while (fw_csr_iterator_next(&it, &key, &val)) {
0182         if (key == CSR_VENDOR)
0183             vendor = val;
0184         else if (key == CSR_MODEL)
0185             model = val;
0186     }
0187 
0188     if (vendor == VENDOR_LOUD) {
0189         // Mackie Onyx Satellite with base station has a quirk to report a wrong
0190         // value in 'dbs' field of CIP header against its format information.
0191         oxfw->quirks |= SND_OXFW_QUIRK_WRONG_DBS;
0192 
0193         // OXFW971-based models may transfer events by blocking method.
0194         if (!(oxfw->quirks & SND_OXFW_QUIRK_JUMBO_PAYLOAD))
0195             oxfw->quirks |= SND_OXFW_QUIRK_BLOCKING_TRANSMISSION;
0196 
0197         if (model == MODEL_ONYX_1640I) {
0198             //Unless receiving packets without NOINFO packet, the device transfers
0199             //mostly half of events in packets than expected.
0200             oxfw->quirks |= SND_OXFW_QUIRK_IGNORE_NO_INFO_PACKET |
0201                     SND_OXFW_QUIRK_VOLUNTARY_RECOVERY;
0202         }
0203     }
0204 
0205     return 0;
0206 }
0207 
0208 static int oxfw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
0209 {
0210     struct snd_card *card;
0211     struct snd_oxfw *oxfw;
0212     int err;
0213 
0214     if (entry->vendor_id == VENDOR_LOUD && entry->model_id == 0 && !detect_loud_models(unit))
0215         return -ENODEV;
0216 
0217     err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*oxfw), &card);
0218     if (err < 0)
0219         return err;
0220     card->private_free = oxfw_card_free;
0221 
0222     oxfw = card->private_data;
0223     oxfw->unit = fw_unit_get(unit);
0224     dev_set_drvdata(&unit->device, oxfw);
0225     oxfw->card = card;
0226 
0227     mutex_init(&oxfw->mutex);
0228     spin_lock_init(&oxfw->lock);
0229     init_waitqueue_head(&oxfw->hwdep_wait);
0230 
0231     err = name_card(oxfw, entry);
0232     if (err < 0)
0233         goto error;
0234 
0235     err = snd_oxfw_stream_discover(oxfw);
0236     if (err < 0)
0237         goto error;
0238 
0239     err = detect_quirks(oxfw, entry);
0240     if (err < 0)
0241         goto error;
0242 
0243     if (oxfw->has_output || oxfw->has_input) {
0244         err = snd_oxfw_stream_init_duplex(oxfw);
0245         if (err < 0)
0246             goto error;
0247 
0248         err = snd_oxfw_create_pcm(oxfw);
0249         if (err < 0)
0250             goto error;
0251 
0252         snd_oxfw_proc_init(oxfw);
0253 
0254         err = snd_oxfw_create_midi(oxfw);
0255         if (err < 0)
0256             goto error;
0257 
0258         err = snd_oxfw_create_hwdep(oxfw);
0259         if (err < 0)
0260             goto error;
0261     }
0262 
0263     err = snd_card_register(card);
0264     if (err < 0)
0265         goto error;
0266 
0267     return 0;
0268 error:
0269     snd_card_free(card);
0270     return err;
0271 }
0272 
0273 static void oxfw_bus_reset(struct fw_unit *unit)
0274 {
0275     struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
0276 
0277     fcp_bus_reset(oxfw->unit);
0278 
0279     if (oxfw->has_output || oxfw->has_input) {
0280         mutex_lock(&oxfw->mutex);
0281         snd_oxfw_stream_update_duplex(oxfw);
0282         mutex_unlock(&oxfw->mutex);
0283     }
0284 
0285     if (oxfw->quirks & SND_OXFW_QUIRK_SCS_TRANSACTION)
0286         snd_oxfw_scs1x_update(oxfw);
0287 }
0288 
0289 static void oxfw_remove(struct fw_unit *unit)
0290 {
0291     struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
0292 
0293     // Block till all of ALSA character devices are released.
0294     snd_card_free(oxfw->card);
0295 }
0296 
0297 static const struct compat_info griffin_firewave = {
0298     .driver_name = "FireWave",
0299     .vendor_name = "Griffin",
0300     .model_name = "FireWave",
0301 };
0302 
0303 static const struct compat_info lacie_speakers = {
0304     .driver_name = "FWSpeakers",
0305     .vendor_name = "LaCie",
0306     .model_name = "FireWire Speakers",
0307 };
0308 
0309 #define OXFW_DEV_ENTRY(vendor, model, data) \
0310 { \
0311     .match_flags  = IEEE1394_MATCH_VENDOR_ID | \
0312             IEEE1394_MATCH_MODEL_ID | \
0313             IEEE1394_MATCH_SPECIFIER_ID | \
0314             IEEE1394_MATCH_VERSION, \
0315     .vendor_id    = vendor, \
0316     .model_id     = model, \
0317     .specifier_id = SPECIFIER_1394TA, \
0318     .version      = VERSION_AVC, \
0319     .driver_data  = (kernel_ulong_t)data, \
0320 }
0321 
0322 static const struct ieee1394_device_id oxfw_id_table[] = {
0323     //
0324     // OXFW970 devices:
0325     // Initial firmware has a quirk to postpone isoc packet transmission during finishing async
0326     // transaction. As a result, several isochronous cycles are skipped to transfer the packets
0327     // and the audio data frames which should have been transferred during the cycles are put
0328     // into packet at the first isoc cycle after the postpone. Furthermore, the value of SYT
0329     // field in CIP header is not reliable as synchronization timing,
0330     //
0331     OXFW_DEV_ENTRY(VENDOR_GRIFFIN, 0x00f970, &griffin_firewave),
0332     OXFW_DEV_ENTRY(VENDOR_LACIE, 0x00f970, &lacie_speakers),
0333     // Behringer,F-Control Audio 202. The value of SYT field is not reliable at all.
0334     OXFW_DEV_ENTRY(VENDOR_BEHRINGER, 0x00fc22, NULL),
0335     // Loud Technologies, Tapco Link.FireWire 4x6. The value of SYT field is always 0xffff.
0336     OXFW_DEV_ENTRY(VENDOR_LOUD, 0x000460, NULL),
0337     // Loud Technologies, Mackie Onyx Satellite. Although revised version of firmware is
0338     // installed to avoid the postpone, the value of SYT field is always 0xffff.
0339     OXFW_DEV_ENTRY(VENDOR_LOUD, MODEL_SATELLITE, NULL),
0340     // Miglia HarmonyAudio. Not yet identified.
0341 
0342     //
0343     // OXFW971 devices:
0344     // The value of SYT field in CIP header is enough reliable. Both of blocking and non-blocking
0345     // transmission methods are available.
0346     //
0347     // Any Mackie(Loud) models (name string/model id):
0348     //  Onyx-i series (former models):  0x081216
0349     //  Onyx 1640i:             0x001640
0350     //  d.2 pro/d.4 pro (built-in card):    Unknown
0351     //  U.420:              Unknown
0352     //  U.420d:             Unknown
0353     {
0354         .match_flags    = IEEE1394_MATCH_VENDOR_ID |
0355                   IEEE1394_MATCH_SPECIFIER_ID |
0356                   IEEE1394_MATCH_VERSION,
0357         .vendor_id  = VENDOR_LOUD,
0358         .model_id   = 0,
0359         .specifier_id   = SPECIFIER_1394TA,
0360         .version    = VERSION_AVC,
0361     },
0362     // TASCAM, FireOne.
0363     OXFW_DEV_ENTRY(VENDOR_TASCAM, 0x800007, NULL),
0364     // Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m).
0365     OXFW_DEV_ENTRY(OUI_STANTON, MODEL_SCS1M, NULL),
0366     // Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d).
0367     OXFW_DEV_ENTRY(OUI_STANTON, 0x002000, NULL),
0368     // APOGEE, duet FireWire.
0369     OXFW_DEV_ENTRY(OUI_APOGEE, MODEL_DUET_FW, NULL),
0370     { }
0371 };
0372 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
0373 
0374 static struct fw_driver oxfw_driver = {
0375     .driver   = {
0376         .owner  = THIS_MODULE,
0377         .name   = KBUILD_MODNAME,
0378         .bus    = &fw_bus_type,
0379     },
0380     .probe    = oxfw_probe,
0381     .update   = oxfw_bus_reset,
0382     .remove   = oxfw_remove,
0383     .id_table = oxfw_id_table,
0384 };
0385 
0386 static int __init snd_oxfw_init(void)
0387 {
0388     return driver_register(&oxfw_driver.driver);
0389 }
0390 
0391 static void __exit snd_oxfw_exit(void)
0392 {
0393     driver_unregister(&oxfw_driver.driver);
0394 }
0395 
0396 module_init(snd_oxfw_init);
0397 module_exit(snd_oxfw_exit);