diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2011-09-04 16:16:02 -0400 |
---|---|---|
committer | Clemens Ladisch <clemens@ladisch.de> | 2013-10-20 16:07:57 -0400 |
commit | cbab328ddc78589233be8be2f1e6a5f9d97b81db (patch) | |
tree | 49fac9dcb4b812c00e06ec010310a2b21bbc6255 /sound/firewire/dice.c | |
parent | 54e72f0ba31e1562e6d6277d0e4d39a7004f814d (diff) |
ALSA: dice: fix device detection for other vendors
DICE devices do not have a unique specifier ID in their unit directory
(it's always the same as the device vendor's ID), so rely on just the
version ID for driver loading, and use a heuristic in the probe callback
to detect actual DICE devices.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'sound/firewire/dice.c')
-rw-r--r-- | sound/firewire/dice.c | 102 |
1 files changed, 84 insertions, 18 deletions
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c index 1da1ddefd6a8..b4827ff45d68 100644 --- a/sound/firewire/dice.c +++ b/sound/firewire/dice.c | |||
@@ -827,28 +827,93 @@ static void dice_card_free(struct snd_card *card) | |||
827 | mutex_destroy(&dice->mutex); | 827 | mutex_destroy(&dice->mutex); |
828 | } | 828 | } |
829 | 829 | ||
830 | #define DICE_CATEGORY_ID 0x04 | ||
831 | |||
832 | static int dice_interface_check(struct fw_unit *unit) | ||
833 | { | ||
834 | static const int min_values[10] = { | ||
835 | 10, 0x64 / 4, | ||
836 | 10, 0x18 / 4, | ||
837 | 10, 0x18 / 4, | ||
838 | 0, 0, | ||
839 | 0, 0, | ||
840 | }; | ||
841 | struct fw_device *device = fw_parent_device(unit); | ||
842 | struct fw_csr_iterator it; | ||
843 | int key, value, vendor = -1, model = -1, err; | ||
844 | unsigned int i; | ||
845 | __be32 pointers[ARRAY_SIZE(min_values)]; | ||
846 | __be32 version; | ||
847 | |||
848 | /* | ||
849 | * Check that GUID and unit directory are constructed according to DICE | ||
850 | * rules, i.e., that the specifier ID is the GUID's OUI, and that the | ||
851 | * GUID chip ID consists of the 8-bit DICE category ID, the 10-bit | ||
852 | * product ID, and a 22-bit serial number. | ||
853 | */ | ||
854 | fw_csr_iterator_init(&it, unit->directory); | ||
855 | while (fw_csr_iterator_next(&it, &key, &value)) { | ||
856 | switch (key) { | ||
857 | case CSR_SPECIFIER_ID: | ||
858 | vendor = value; | ||
859 | break; | ||
860 | case CSR_MODEL: | ||
861 | model = value; | ||
862 | break; | ||
863 | } | ||
864 | } | ||
865 | if (device->config_rom[3] != ((vendor << 8) | DICE_CATEGORY_ID) || | ||
866 | device->config_rom[4] >> 22 != model) | ||
867 | return -ENODEV; | ||
868 | |||
869 | /* | ||
870 | * Check that the sub address spaces exist and are located inside the | ||
871 | * private address space. The minimum values are chosen so that all | ||
872 | * minimally required registers are included. | ||
873 | */ | ||
874 | err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, | ||
875 | DICE_PRIVATE_SPACE, | ||
876 | pointers, sizeof(pointers)); | ||
877 | if (err < 0) | ||
878 | return -ENODEV; | ||
879 | for (i = 0; i < ARRAY_SIZE(pointers); ++i) { | ||
880 | value = be32_to_cpu(pointers[i]); | ||
881 | if (value < min_values[i] || value >= 0x40000) | ||
882 | return -ENODEV; | ||
883 | } | ||
884 | |||
885 | /* | ||
886 | * Check that the implemented DICE driver specification major version | ||
887 | * number matches. | ||
888 | */ | ||
889 | err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, | ||
890 | DICE_PRIVATE_SPACE + | ||
891 | be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION, | ||
892 | &version, 4); | ||
893 | if (err < 0) | ||
894 | return -ENODEV; | ||
895 | if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) { | ||
896 | dev_err(&unit->device, | ||
897 | "unknown DICE version: 0x%08x\n", be32_to_cpu(version)); | ||
898 | return -ENODEV; | ||
899 | } | ||
900 | |||
901 | return 0; | ||
902 | } | ||
903 | |||
830 | static int dice_init_offsets(struct dice *dice) | 904 | static int dice_init_offsets(struct dice *dice) |
831 | { | 905 | { |
832 | __be32 pointers[6]; | 906 | __be32 pointers[6]; |
833 | unsigned int global_size, rx_size; | ||
834 | int err; | 907 | int err; |
835 | 908 | ||
836 | err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST, | 909 | err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST, |
837 | DICE_PRIVATE_SPACE, &pointers, 6 * 4); | 910 | DICE_PRIVATE_SPACE, |
911 | pointers, sizeof(pointers)); | ||
838 | if (err < 0) | 912 | if (err < 0) |
839 | return err; | 913 | return err; |
840 | 914 | ||
841 | dice->global_offset = be32_to_cpu(pointers[0]) * 4; | 915 | dice->global_offset = be32_to_cpu(pointers[0]) * 4; |
842 | global_size = be32_to_cpu(pointers[1]); | ||
843 | dice->rx_offset = be32_to_cpu(pointers[4]) * 4; | 916 | dice->rx_offset = be32_to_cpu(pointers[4]) * 4; |
844 | rx_size = be32_to_cpu(pointers[5]); | ||
845 | |||
846 | /* some sanity checks to ensure that we actually have a DICE */ | ||
847 | if (dice->global_offset < 10 * 4 || global_size < 0x168 / 4 || | ||
848 | dice->rx_offset < 10 * 4 || rx_size < 0x120 / 4) { | ||
849 | dev_err(&dice->unit->device, "invalid register pointers\n"); | ||
850 | return -ENXIO; | ||
851 | } | ||
852 | 917 | ||
853 | return 0; | 918 | return 0; |
854 | } | 919 | } |
@@ -881,8 +946,8 @@ static void dice_card_strings(struct dice *dice) | |||
881 | strcpy(model, "?"); | 946 | strcpy(model, "?"); |
882 | fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model)); | 947 | fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model)); |
883 | snprintf(card->longname, sizeof(card->longname), | 948 | snprintf(card->longname, sizeof(card->longname), |
884 | "%s %s, GUID %08x%08x at %s, S%d", | 949 | "%s %s (serial %u) at %s, S%d", |
885 | vendor, model, dev->config_rom[3], dev->config_rom[4], | 950 | vendor, model, dev->config_rom[4] & 0x3fffff, |
886 | dev_name(&dice->unit->device), 100 << dev->max_speed); | 951 | dev_name(&dice->unit->device), 100 << dev->max_speed); |
887 | 952 | ||
888 | strcpy(card->mixername, "DICE"); | 953 | strcpy(card->mixername, "DICE"); |
@@ -895,6 +960,10 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id) | |||
895 | __be32 clock_sel; | 960 | __be32 clock_sel; |
896 | int err; | 961 | int err; |
897 | 962 | ||
963 | err = dice_interface_check(unit); | ||
964 | if (err < 0) | ||
965 | return err; | ||
966 | |||
898 | err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*dice), &card); | 967 | err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*dice), &card); |
899 | if (err < 0) | 968 | if (err < 0) |
900 | return err; | 969 | return err; |
@@ -1020,15 +1089,12 @@ static void dice_bus_reset(struct fw_unit *unit) | |||
1020 | mutex_unlock(&dice->mutex); | 1089 | mutex_unlock(&dice->mutex); |
1021 | } | 1090 | } |
1022 | 1091 | ||
1023 | #define TC_OUI 0x000166 | ||
1024 | #define DICE_INTERFACE 0x000001 | 1092 | #define DICE_INTERFACE 0x000001 |
1025 | 1093 | ||
1026 | static const struct ieee1394_device_id dice_id_table[] = { | 1094 | static const struct ieee1394_device_id dice_id_table[] = { |
1027 | { | 1095 | { |
1028 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | | 1096 | .match_flags = IEEE1394_MATCH_VERSION, |
1029 | IEEE1394_MATCH_VERSION, | 1097 | .version = DICE_INTERFACE, |
1030 | .specifier_id = TC_OUI, | ||
1031 | .version = DICE_INTERFACE, | ||
1032 | }, | 1098 | }, |
1033 | { } | 1099 | { } |
1034 | }; | 1100 | }; |