0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "dice.h"
0010
0011 static int dice_proc_read_mem(struct snd_dice *dice, void *buffer,
0012 unsigned int offset_q, unsigned int quadlets)
0013 {
0014 unsigned int i;
0015 int err;
0016
0017 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
0018 DICE_PRIVATE_SPACE + 4 * offset_q,
0019 buffer, 4 * quadlets, 0);
0020 if (err < 0)
0021 return err;
0022
0023 for (i = 0; i < quadlets; ++i)
0024 be32_to_cpus(&((u32 *)buffer)[i]);
0025
0026 return 0;
0027 }
0028
0029 static const char *str_from_array(const char *const strs[], unsigned int count,
0030 unsigned int i)
0031 {
0032 if (i < count)
0033 return strs[i];
0034
0035 return "(unknown)";
0036 }
0037
0038 static void dice_proc_fixup_string(char *s, unsigned int size)
0039 {
0040 unsigned int i;
0041
0042 for (i = 0; i < size; i += 4)
0043 cpu_to_le32s((u32 *)(s + i));
0044
0045 for (i = 0; i < size - 2; ++i) {
0046 if (s[i] == '\0')
0047 return;
0048 if (s[i] == '\\' && s[i + 1] == '\\') {
0049 s[i + 2] = '\0';
0050 return;
0051 }
0052 }
0053 s[size - 1] = '\0';
0054 }
0055
0056 static void dice_proc_read(struct snd_info_entry *entry,
0057 struct snd_info_buffer *buffer)
0058 {
0059 static const char *const section_names[5] = {
0060 "global", "tx", "rx", "ext_sync", "unused2"
0061 };
0062 static const char *const clock_sources[] = {
0063 "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif",
0064 "wc", "arx1", "arx2", "arx3", "arx4", "internal"
0065 };
0066 static const char *const rates[] = {
0067 "32000", "44100", "48000", "88200", "96000", "176400", "192000",
0068 "any low", "any mid", "any high", "none"
0069 };
0070 struct snd_dice *dice = entry->private_data;
0071 u32 sections[ARRAY_SIZE(section_names) * 2];
0072 struct {
0073 u32 number;
0074 u32 size;
0075 } tx_rx_header;
0076 union {
0077 struct {
0078 u32 owner_hi, owner_lo;
0079 u32 notification;
0080 char nick_name[NICK_NAME_SIZE];
0081 u32 clock_select;
0082 u32 enable;
0083 u32 status;
0084 u32 extended_status;
0085 u32 sample_rate;
0086 u32 version;
0087 u32 clock_caps;
0088 char clock_source_names[CLOCK_SOURCE_NAMES_SIZE];
0089 } global;
0090 struct {
0091 u32 iso;
0092 u32 number_audio;
0093 u32 number_midi;
0094 u32 speed;
0095 char names[TX_NAMES_SIZE];
0096 u32 ac3_caps;
0097 u32 ac3_enable;
0098 } tx;
0099 struct {
0100 u32 iso;
0101 u32 seq_start;
0102 u32 number_audio;
0103 u32 number_midi;
0104 char names[RX_NAMES_SIZE];
0105 u32 ac3_caps;
0106 u32 ac3_enable;
0107 } rx;
0108 struct {
0109 u32 clock_source;
0110 u32 locked;
0111 u32 rate;
0112 u32 adat_user_data;
0113 } ext_sync;
0114 } buf;
0115 unsigned int quadlets, stream, i;
0116
0117 if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0)
0118 return;
0119 snd_iprintf(buffer, "sections:\n");
0120 for (i = 0; i < ARRAY_SIZE(section_names); ++i)
0121 snd_iprintf(buffer, " %s: offset %u, size %u\n",
0122 section_names[i],
0123 sections[i * 2], sections[i * 2 + 1]);
0124
0125 quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4);
0126 if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0)
0127 return;
0128 snd_iprintf(buffer, "global:\n");
0129 snd_iprintf(buffer, " owner: %04x:%04x%08x\n",
0130 buf.global.owner_hi >> 16,
0131 buf.global.owner_hi & 0xffff, buf.global.owner_lo);
0132 snd_iprintf(buffer, " notification: %08x\n", buf.global.notification);
0133 dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE);
0134 snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name);
0135 snd_iprintf(buffer, " clock select: %s %s\n",
0136 str_from_array(clock_sources, ARRAY_SIZE(clock_sources),
0137 buf.global.clock_select & CLOCK_SOURCE_MASK),
0138 str_from_array(rates, ARRAY_SIZE(rates),
0139 (buf.global.clock_select & CLOCK_RATE_MASK)
0140 >> CLOCK_RATE_SHIFT));
0141 snd_iprintf(buffer, " enable: %u\n", buf.global.enable);
0142 snd_iprintf(buffer, " status: %slocked %s\n",
0143 buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un",
0144 str_from_array(rates, ARRAY_SIZE(rates),
0145 (buf.global.status &
0146 STATUS_NOMINAL_RATE_MASK)
0147 >> CLOCK_RATE_SHIFT));
0148 snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status);
0149 snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate);
0150 if (quadlets >= 90) {
0151 snd_iprintf(buffer, " version: %u.%u.%u.%u\n",
0152 (buf.global.version >> 24) & 0xff,
0153 (buf.global.version >> 16) & 0xff,
0154 (buf.global.version >> 8) & 0xff,
0155 (buf.global.version >> 0) & 0xff);
0156 snd_iprintf(buffer, " clock caps:");
0157 for (i = 0; i <= 6; ++i)
0158 if (buf.global.clock_caps & (1 << i))
0159 snd_iprintf(buffer, " %s", rates[i]);
0160 for (i = 0; i <= 12; ++i)
0161 if (buf.global.clock_caps & (1 << (16 + i)))
0162 snd_iprintf(buffer, " %s", clock_sources[i]);
0163 snd_iprintf(buffer, "\n");
0164 dice_proc_fixup_string(buf.global.clock_source_names,
0165 CLOCK_SOURCE_NAMES_SIZE);
0166 snd_iprintf(buffer, " clock source names: %s\n",
0167 buf.global.clock_source_names);
0168 }
0169
0170 if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
0171 return;
0172 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
0173 for (stream = 0; stream < tx_rx_header.number; ++stream) {
0174 if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
0175 stream * tx_rx_header.size,
0176 quadlets) < 0)
0177 break;
0178 snd_iprintf(buffer, "tx %u:\n", stream);
0179 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso);
0180 snd_iprintf(buffer, " audio channels: %u\n",
0181 buf.tx.number_audio);
0182 snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi);
0183 snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed);
0184 if (quadlets >= 68) {
0185 dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE);
0186 snd_iprintf(buffer, " names: %s\n", buf.tx.names);
0187 }
0188 if (quadlets >= 70) {
0189 snd_iprintf(buffer, " ac3 caps: %08x\n",
0190 buf.tx.ac3_caps);
0191 snd_iprintf(buffer, " ac3 enable: %08x\n",
0192 buf.tx.ac3_enable);
0193 }
0194 }
0195
0196 if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
0197 return;
0198 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
0199 for (stream = 0; stream < tx_rx_header.number; ++stream) {
0200 if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
0201 stream * tx_rx_header.size,
0202 quadlets) < 0)
0203 break;
0204 snd_iprintf(buffer, "rx %u:\n", stream);
0205 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso);
0206 snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start);
0207 snd_iprintf(buffer, " audio channels: %u\n",
0208 buf.rx.number_audio);
0209 snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi);
0210 if (quadlets >= 68) {
0211 dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE);
0212 snd_iprintf(buffer, " names: %s\n", buf.rx.names);
0213 }
0214 if (quadlets >= 70) {
0215 snd_iprintf(buffer, " ac3 caps: %08x\n",
0216 buf.rx.ac3_caps);
0217 snd_iprintf(buffer, " ac3 enable: %08x\n",
0218 buf.rx.ac3_enable);
0219 }
0220 }
0221
0222 quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4);
0223 if (quadlets >= 4) {
0224 if (dice_proc_read_mem(dice, &buf.ext_sync,
0225 sections[6], 4) < 0)
0226 return;
0227 snd_iprintf(buffer, "ext status:\n");
0228 snd_iprintf(buffer, " clock source: %s\n",
0229 str_from_array(clock_sources,
0230 ARRAY_SIZE(clock_sources),
0231 buf.ext_sync.clock_source));
0232 snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked);
0233 snd_iprintf(buffer, " rate: %s\n",
0234 str_from_array(rates, ARRAY_SIZE(rates),
0235 buf.ext_sync.rate));
0236 snd_iprintf(buffer, " adat user data: ");
0237 if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA)
0238 snd_iprintf(buffer, "-\n");
0239 else
0240 snd_iprintf(buffer, "%x\n",
0241 buf.ext_sync.adat_user_data);
0242 }
0243 }
0244
0245 static void dice_proc_read_formation(struct snd_info_entry *entry,
0246 struct snd_info_buffer *buffer)
0247 {
0248 static const char *const rate_labels[] = {
0249 [SND_DICE_RATE_MODE_LOW] = "low",
0250 [SND_DICE_RATE_MODE_MIDDLE] = "middle",
0251 [SND_DICE_RATE_MODE_HIGH] = "high",
0252 };
0253 struct snd_dice *dice = entry->private_data;
0254 int i, j;
0255
0256 snd_iprintf(buffer, "Output stream from unit:\n");
0257 for (i = 0; i < SND_DICE_RATE_MODE_COUNT; ++i)
0258 snd_iprintf(buffer, "\t%s", rate_labels[i]);
0259 snd_iprintf(buffer, "\tMIDI\n");
0260 for (i = 0; i < MAX_STREAMS; ++i) {
0261 snd_iprintf(buffer, "Tx %u:", i);
0262 for (j = 0; j < SND_DICE_RATE_MODE_COUNT; ++j)
0263 snd_iprintf(buffer, "\t%u", dice->tx_pcm_chs[i][j]);
0264 snd_iprintf(buffer, "\t%u\n", dice->tx_midi_ports[i]);
0265 }
0266
0267 snd_iprintf(buffer, "Input stream to unit:\n");
0268 for (i = 0; i < SND_DICE_RATE_MODE_COUNT; ++i)
0269 snd_iprintf(buffer, "\t%s", rate_labels[i]);
0270 snd_iprintf(buffer, "\n");
0271 for (i = 0; i < MAX_STREAMS; ++i) {
0272 snd_iprintf(buffer, "Rx %u:", i);
0273 for (j = 0; j < SND_DICE_RATE_MODE_COUNT; ++j)
0274 snd_iprintf(buffer, "\t%u", dice->rx_pcm_chs[i][j]);
0275 snd_iprintf(buffer, "\t%u\n", dice->rx_midi_ports[i]);
0276 }
0277 }
0278
0279 static void add_node(struct snd_dice *dice, struct snd_info_entry *root,
0280 const char *name,
0281 void (*op)(struct snd_info_entry *entry,
0282 struct snd_info_buffer *buffer))
0283 {
0284 struct snd_info_entry *entry;
0285
0286 entry = snd_info_create_card_entry(dice->card, name, root);
0287 if (entry)
0288 snd_info_set_text_ops(entry, dice, op);
0289 }
0290
0291 void snd_dice_create_proc(struct snd_dice *dice)
0292 {
0293 struct snd_info_entry *root;
0294
0295
0296
0297
0298
0299 root = snd_info_create_card_entry(dice->card, "firewire",
0300 dice->card->proc_root);
0301 if (!root)
0302 return;
0303 root->mode = S_IFDIR | 0555;
0304
0305 add_node(dice, root, "dice", dice_proc_read);
0306 add_node(dice, root, "formation", dice_proc_read_formation);
0307 }