1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 4 * Creative Labs, Inc. 5 * Routines for control of EMU10K1 chips / proc interface routines 6 * 7 * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk> 8 * Added EMU 1010 support. 9 * 10 * BUGS: 11 * -- 12 * 13 * TODO: 14 * -- 15 */ 16 17 #include <linux/slab.h> 18 #include <linux/init.h> 19 #include <sound/core.h> 20 #include <sound/emu10k1.h> 21 #include "p16v.h" 22 23 static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu, 24 struct snd_info_buffer *buffer, 25 char *title, 26 int status_reg, 27 int rate_reg) 28 { 29 static const char * const clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" }; 30 static const int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; 31 static const char * const channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }; 32 static const char * const emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" }; 33 unsigned int status, rate = 0; 34 35 status = snd_emu10k1_ptr_read(emu, status_reg, 0); 36 37 snd_iprintf(buffer, "\n%s\n", title); 38 39 if (status != 0xffffffff) { 40 snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no"); 41 snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no"); 42 snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no"); 43 snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]); 44 snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6); 45 snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8); 46 snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy"); 47 snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16); 48 snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]); 49 snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]); 50 snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]); 51 52 if (rate_reg > 0) { 53 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0); 54 snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off"); 55 snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off"); 56 snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off"); 57 /* From ((Rate * 48000 ) / 262144); */ 58 snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11); 59 } 60 } else { 61 snd_iprintf(buffer, "No signal detected.\n"); 62 } 63 64 } 65 66 static void snd_emu10k1_proc_read(struct snd_info_entry *entry, 67 struct snd_info_buffer *buffer) 68 { 69 struct snd_emu10k1 *emu = entry->private_data; 70 const char * const *inputs = emu->audigy ? 71 snd_emu10k1_audigy_ins : snd_emu10k1_sblive_ins; 72 const char * const *outputs = emu->audigy ? 73 snd_emu10k1_audigy_outs : snd_emu10k1_sblive_outs; 74 unsigned short extin_mask = emu->audigy ? ~0 : emu->fx8010.extin_mask; 75 unsigned short extout_mask = emu->audigy ? ~0 : emu->fx8010.extout_mask; 76 unsigned int val, val1, ptrx, psst, dsl, snda; 77 int nefx = emu->audigy ? 32 : 16; 78 int idx; 79 80 snd_iprintf(buffer, "EMU10K1\n\n"); 81 snd_iprintf(buffer, "Card : %s\n", 82 emu->card_capabilities->emu_model ? "E-MU D.A.S." : 83 emu->card_capabilities->ecard ? "E-MU A.P.S." : 84 emu->audigy ? "SB Audigy" : "SB Live!"); 85 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size); 86 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2); 87 88 snd_iprintf(buffer, "\nEffect Send Routing & Amounts:\n"); 89 for (idx = 0; idx < NUM_G; idx++) { 90 ptrx = snd_emu10k1_ptr_read(emu, PTRX, idx); 91 psst = snd_emu10k1_ptr_read(emu, PSST, idx); 92 dsl = snd_emu10k1_ptr_read(emu, DSL, idx); 93 if (emu->audigy) { 94 val = snd_emu10k1_ptr_read(emu, A_FXRT1, idx); 95 val1 = snd_emu10k1_ptr_read(emu, A_FXRT2, idx); 96 snda = snd_emu10k1_ptr_read(emu, A_SENDAMOUNTS, idx); 97 snd_iprintf(buffer, "Ch%-2i: A=%2i:%02x, B=%2i:%02x, C=%2i:%02x, D=%2i:%02x, ", 98 idx, 99 val & 0x3f, REG_VAL_GET(PTRX_FXSENDAMOUNT_A, ptrx), 100 (val >> 8) & 0x3f, REG_VAL_GET(PTRX_FXSENDAMOUNT_B, ptrx), 101 (val >> 16) & 0x3f, REG_VAL_GET(PSST_FXSENDAMOUNT_C, psst), 102 (val >> 24) & 0x3f, REG_VAL_GET(DSL_FXSENDAMOUNT_D, dsl)); 103 snd_iprintf(buffer, "E=%2i:%02x, F=%2i:%02x, G=%2i:%02x, H=%2i:%02x\n", 104 val1 & 0x3f, (snda >> 24) & 0xff, 105 (val1 >> 8) & 0x3f, (snda >> 16) & 0xff, 106 (val1 >> 16) & 0x3f, (snda >> 8) & 0xff, 107 (val1 >> 24) & 0x3f, snda & 0xff); 108 } else { 109 val = snd_emu10k1_ptr_read(emu, FXRT, idx); 110 snd_iprintf(buffer, "Ch%-2i: A=%2i:%02x, B=%2i:%02x, C=%2i:%02x, D=%2i:%02x\n", 111 idx, 112 (val >> 16) & 0x0f, REG_VAL_GET(PTRX_FXSENDAMOUNT_A, ptrx), 113 (val >> 20) & 0x0f, REG_VAL_GET(PTRX_FXSENDAMOUNT_B, ptrx), 114 (val >> 24) & 0x0f, REG_VAL_GET(PSST_FXSENDAMOUNT_C, psst), 115 (val >> 28) & 0x0f, REG_VAL_GET(DSL_FXSENDAMOUNT_D, dsl)); 116 } 117 } 118 snd_iprintf(buffer, "\nEffect Send Targets:\n"); 119 // Audigy actually has 64, but we don't use them all. 120 for (idx = 0; idx < 32; idx++) { 121 const char *c = snd_emu10k1_fxbus[idx]; 122 if (c) 123 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, c); 124 } 125 if (!emu->card_capabilities->emu_model) { 126 snd_iprintf(buffer, "\nOutput Channels:\n"); 127 for (idx = 0; idx < 32; idx++) 128 if (outputs[idx] && (extout_mask & (1 << idx))) 129 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, outputs[idx]); 130 snd_iprintf(buffer, "\nInput Channels:\n"); 131 for (idx = 0; idx < 16; idx++) 132 if (inputs[idx] && (extin_mask & (1 << idx))) 133 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, inputs[idx]); 134 snd_iprintf(buffer, "\nMultichannel Capture Sources:\n"); 135 for (idx = 0; idx < nefx; idx++) 136 if (emu->efx_voices_mask[0] & (1 << idx)) 137 snd_iprintf(buffer, " Channel %02i [Output: %s]\n", 138 idx, outputs[idx] ? outputs[idx] : "???"); 139 if (emu->audigy) { 140 for (idx = 0; idx < 32; idx++) 141 if (emu->efx_voices_mask[1] & (1 << idx)) 142 snd_iprintf(buffer, " Channel %02i [Input: %s]\n", 143 idx + 32, inputs[idx] ? inputs[idx] : "???"); 144 } else { 145 for (idx = 0; idx < 16; idx++) { 146 if (emu->efx_voices_mask[0] & ((1 << 16) << idx)) { 147 if (emu->card_capabilities->sblive51) { 148 s8 c = snd_emu10k1_sblive51_fxbus2_map[idx]; 149 if (c == -1) 150 snd_iprintf(buffer, " Channel %02i [Output: %s]\n", 151 idx + 16, outputs[idx + 16]); 152 else 153 snd_iprintf(buffer, " Channel %02i [Input: %s]\n", 154 idx + 16, inputs[c]); 155 } else { 156 snd_iprintf(buffer, " Channel %02i [Input: %s]\n", 157 idx + 16, inputs[idx] ? inputs[idx] : "???"); 158 } 159 } 160 } 161 } 162 } 163 } 164 165 static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, 166 struct snd_info_buffer *buffer) 167 { 168 struct snd_emu10k1 *emu = entry->private_data; 169 u32 value; 170 u32 value2; 171 u32 rate; 172 173 if (emu->card_capabilities->emu_model) { 174 if (!emu->card_capabilities->no_adat) { 175 snd_emu1010_fpga_read(emu, 0x38, &value); 176 if ((value & 0x1) == 0) { 177 snd_emu1010_fpga_read(emu, 0x2a, &value); 178 snd_emu1010_fpga_read(emu, 0x2b, &value2); 179 rate = 0x1770000 / (((value << 5) | value2)+1); 180 snd_iprintf(buffer, "ADAT Locked : %u\n", rate); 181 } else { 182 snd_iprintf(buffer, "ADAT Unlocked\n"); 183 } 184 } 185 snd_emu1010_fpga_read(emu, 0x20, &value); 186 if ((value & 0x4) == 0) { 187 snd_emu1010_fpga_read(emu, 0x28, &value); 188 snd_emu1010_fpga_read(emu, 0x29, &value2); 189 rate = 0x1770000 / (((value << 5) | value2)+1); 190 snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); 191 } else { 192 snd_iprintf(buffer, "SPDIF Unlocked\n"); 193 } 194 } else { 195 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS); 196 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS); 197 } 198 #if 0 199 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0); 200 snd_iprintf(buffer, "\nZoomed Video\n"); 201 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off"); 202 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE); 203 #endif 204 } 205 206 static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry, 207 struct snd_info_buffer *buffer) 208 { 209 static const int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 }; 210 struct snd_emu10k1 *emu = entry->private_data; 211 unsigned int val, tmp, n; 212 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0); 213 for (n = 0; n < 4; n++) { 214 tmp = val >> (16 + (n*4)); 215 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]); 216 else snd_iprintf(buffer, "Channel %d: No input\n", n); 217 } 218 } 219 220 struct emu10k1_reg_entry { 221 unsigned short base, size; 222 const char *name; 223 }; 224 225 static const struct emu10k1_reg_entry sblive_reg_entries[] = { 226 { 0, 0x10, "FXBUS" }, 227 { 0x10, 0x10, "EXTIN" }, 228 { 0x20, 0x10, "EXTOUT" }, 229 { 0x30, 0x10, "FXBUS2" }, 230 { 0x40, 0x20, NULL }, // Constants 231 { 0x100, 0x100, "GPR" }, 232 { 0x200, 0x80, "ITRAM_DATA" }, 233 { 0x280, 0x20, "ETRAM_DATA" }, 234 { 0x300, 0x80, "ITRAM_ADDR" }, 235 { 0x380, 0x20, "ETRAM_ADDR" }, 236 { 0x400, 0, NULL } 237 }; 238 239 static const struct emu10k1_reg_entry audigy_reg_entries[] = { 240 { 0, 0x40, "FXBUS" }, 241 { 0x40, 0x10, "EXTIN" }, 242 { 0x50, 0x10, "P16VIN" }, 243 { 0x60, 0x20, "EXTOUT" }, 244 { 0x80, 0x20, "FXBUS2" }, 245 { 0xa0, 0x10, "EMU32OUTH" }, 246 { 0xb0, 0x10, "EMU32OUTL" }, 247 { 0xc0, 0x20, NULL }, // Constants 248 // This can't be quite right - overlap. 249 //{ 0x100, 0xc0, "ITRAM_CTL" }, 250 //{ 0x1c0, 0x40, "ETRAM_CTL" }, 251 { 0x160, 0x20, "A3_EMU32IN" }, 252 { 0x1e0, 0x20, "A3_EMU32OUT" }, 253 { 0x200, 0xc0, "ITRAM_DATA" }, 254 { 0x2c0, 0x40, "ETRAM_DATA" }, 255 { 0x300, 0xc0, "ITRAM_ADDR" }, 256 { 0x3c0, 0x40, "ETRAM_ADDR" }, 257 { 0x400, 0x200, "GPR" }, 258 { 0x600, 0, NULL } 259 }; 260 261 static const char * const emu10k1_const_entries[] = { 262 "C_00000000", 263 "C_00000001", 264 "C_00000002", 265 "C_00000003", 266 "C_00000004", 267 "C_00000008", 268 "C_00000010", 269 "C_00000020", 270 "C_00000100", 271 "C_00010000", 272 "C_00000800", 273 "C_10000000", 274 "C_20000000", 275 "C_40000000", 276 "C_80000000", 277 "C_7fffffff", 278 "C_ffffffff", 279 "C_fffffffe", 280 "C_c0000000", 281 "C_4f1bbcdc", 282 "C_5a7ef9db", 283 "C_00100000", 284 "GPR_ACCU", 285 "GPR_COND", 286 "GPR_NOISE0", 287 "GPR_NOISE1", 288 "GPR_IRQ", 289 "GPR_DBAC", 290 "GPR_DBACE", 291 "???", 292 }; 293 294 static int disasm_emu10k1_reg(char *buffer, 295 const struct emu10k1_reg_entry *entries, 296 unsigned reg, const char *pfx) 297 { 298 for (int i = 0; ; i++) { 299 unsigned base = entries[i].base; 300 unsigned size = entries[i].size; 301 if (!size) 302 return sprintf(buffer, "%s0x%03x", pfx, reg); 303 if (reg >= base && reg < base + size) { 304 const char *name = entries[i].name; 305 reg -= base; 306 if (name) 307 return sprintf(buffer, "%s%s(%u)", pfx, name, reg); 308 return sprintf(buffer, "%s%s", pfx, emu10k1_const_entries[reg]); 309 } 310 } 311 } 312 313 static int disasm_sblive_reg(char *buffer, unsigned reg, const char *pfx) 314 { 315 return disasm_emu10k1_reg(buffer, sblive_reg_entries, reg, pfx); 316 } 317 318 static int disasm_audigy_reg(char *buffer, unsigned reg, const char *pfx) 319 { 320 return disasm_emu10k1_reg(buffer, audigy_reg_entries, reg, pfx); 321 } 322 323 static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry, 324 struct snd_info_buffer *buffer) 325 { 326 u32 pc; 327 struct snd_emu10k1 *emu = entry->private_data; 328 static const char * const insns[16] = { 329 "MAC0", "MAC1", "MAC2", "MAC3", "MACINT0", "MACINT1", "ACC3", "MACMV", 330 "ANDXOR", "TSTNEG", "LIMITGE", "LIMITLT", "LOG", "EXP", "INTERP", "SKIP", 331 }; 332 static const char spaces[] = " "; 333 const int nspaces = sizeof(spaces) - 1; 334 335 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name); 336 snd_iprintf(buffer, " Code dump :\n"); 337 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) { 338 u32 low, high; 339 int len; 340 char buf[100]; 341 char *bufp = buf; 342 343 low = snd_emu10k1_efx_read(emu, pc * 2); 344 high = snd_emu10k1_efx_read(emu, pc * 2 + 1); 345 if (emu->audigy) { 346 bufp += sprintf(bufp, " %-7s ", insns[(high >> 24) & 0x0f]); 347 bufp += disasm_audigy_reg(bufp, (high >> 12) & 0x7ff, ""); 348 bufp += disasm_audigy_reg(bufp, (high >> 0) & 0x7ff, ", "); 349 bufp += disasm_audigy_reg(bufp, (low >> 12) & 0x7ff, ", "); 350 bufp += disasm_audigy_reg(bufp, (low >> 0) & 0x7ff, ", "); 351 } else { 352 bufp += sprintf(bufp, " %-7s ", insns[(high >> 20) & 0x0f]); 353 bufp += disasm_sblive_reg(bufp, (high >> 10) & 0x3ff, ""); 354 bufp += disasm_sblive_reg(bufp, (high >> 0) & 0x3ff, ", "); 355 bufp += disasm_sblive_reg(bufp, (low >> 10) & 0x3ff, ", "); 356 bufp += disasm_sblive_reg(bufp, (low >> 0) & 0x3ff, ", "); 357 } 358 len = (int)(ptrdiff_t)(bufp - buf); 359 snd_iprintf(buffer, "%s %s /* 0x%04x: 0x%08x%08x */\n", 360 buf, &spaces[nspaces - clamp(65 - len, 0, nspaces)], 361 pc, high, low); 362 } 363 } 364 365 #define TOTAL_SIZE_GPR (0x100*4) 366 #define A_TOTAL_SIZE_GPR (0x200*4) 367 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4) 368 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4) 369 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4) 370 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4) 371 #define TOTAL_SIZE_CODE (0x200*8) 372 #define A_TOTAL_SIZE_CODE (0x400*8) 373 374 static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry, 375 void *file_private_data, 376 struct file *file, char __user *buf, 377 size_t count, loff_t pos) 378 { 379 struct snd_emu10k1 *emu = entry->private_data; 380 unsigned int offset; 381 int tram_addr = 0; 382 unsigned int *tmp; 383 long res; 384 unsigned int idx; 385 386 if (!strcmp(entry->name, "fx8010_tram_addr")) { 387 offset = TANKMEMADDRREGBASE; 388 tram_addr = 1; 389 } else if (!strcmp(entry->name, "fx8010_tram_data")) { 390 offset = TANKMEMDATAREGBASE; 391 } else if (!strcmp(entry->name, "fx8010_code")) { 392 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE; 393 } else { 394 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE; 395 } 396 397 tmp = kmalloc(count + 8, GFP_KERNEL); 398 if (!tmp) 399 return -ENOMEM; 400 for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) { 401 unsigned int val; 402 val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0); 403 if (tram_addr && emu->audigy) { 404 val >>= 11; 405 val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20; 406 } 407 tmp[idx] = val; 408 } 409 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count)) 410 res = -EFAULT; 411 else 412 res = count; 413 kfree(tmp); 414 return res; 415 } 416 417 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry, 418 struct snd_info_buffer *buffer) 419 { 420 struct snd_emu10k1 *emu = entry->private_data; 421 struct snd_emu10k1_voice *voice; 422 int idx; 423 static const char * const types[] = { 424 "Unused", "EFX", "EFX IRQ", "PCM", "PCM IRQ", "Synth" 425 }; 426 static_assert(ARRAY_SIZE(types) == EMU10K1_NUM_TYPES); 427 428 snd_iprintf(buffer, "ch\tdirty\tlast\tuse\n"); 429 for (idx = 0; idx < NUM_G; idx++) { 430 voice = &emu->voices[idx]; 431 snd_iprintf(buffer, "%i\t%u\t%u\t%s\n", 432 idx, 433 voice->dirty, 434 voice->last, 435 types[voice->use]); 436 } 437 } 438 439 #ifdef CONFIG_SND_DEBUG 440 441 static void snd_emu_proc_emu1010_link_read(struct snd_emu10k1 *emu, 442 struct snd_info_buffer *buffer, 443 u32 dst) 444 { 445 u32 src = snd_emu1010_fpga_link_dst_src_read(emu, dst); 446 snd_iprintf(buffer, "%04x: %04x\n", dst, src); 447 } 448 449 static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, 450 struct snd_info_buffer *buffer) 451 { 452 struct snd_emu10k1 *emu = entry->private_data; 453 u32 value; 454 int i; 455 snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 456 457 for(i = 0; i < 0x40; i+=1) { 458 snd_emu1010_fpga_read(emu, i, &value); 459 snd_iprintf(buffer, "%02x: %02x\n", i, value); 460 } 461 462 snd_iprintf(buffer, "\nEMU1010 Routes:\n\n"); 463 464 for (i = 0; i < 16; i++) // To Alice2/Tina[2] via EMU32 465 snd_emu_proc_emu1010_link_read(emu, buffer, i); 466 if (emu->card_capabilities->emu_model != EMU_MODEL_EMU0404) 467 for (i = 0; i < 32; i++) // To Dock via EDI 468 snd_emu_proc_emu1010_link_read(emu, buffer, 0x100 + i); 469 if (emu->card_capabilities->emu_model != EMU_MODEL_EMU1616) 470 for (i = 0; i < 8; i++) // To Hamoa/local 471 snd_emu_proc_emu1010_link_read(emu, buffer, 0x200 + i); 472 for (i = 0; i < 8; i++) // To Hamoa/Mana/local 473 snd_emu_proc_emu1010_link_read(emu, buffer, 0x300 + i); 474 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) { 475 for (i = 0; i < 16; i++) // To Tina2 via EMU32 476 snd_emu_proc_emu1010_link_read(emu, buffer, 0x400 + i); 477 } else if (emu->card_capabilities->emu_model != EMU_MODEL_EMU0404) { 478 for (i = 0; i < 8; i++) // To Hana ADAT 479 snd_emu_proc_emu1010_link_read(emu, buffer, 0x400 + i); 480 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010B) { 481 for (i = 0; i < 16; i++) // To Tina via EMU32 482 snd_emu_proc_emu1010_link_read(emu, buffer, 0x500 + i); 483 } else { 484 // To Alice2 via I2S 485 snd_emu_proc_emu1010_link_read(emu, buffer, 0x500); 486 snd_emu_proc_emu1010_link_read(emu, buffer, 0x501); 487 snd_emu_proc_emu1010_link_read(emu, buffer, 0x600); 488 snd_emu_proc_emu1010_link_read(emu, buffer, 0x601); 489 snd_emu_proc_emu1010_link_read(emu, buffer, 0x700); 490 snd_emu_proc_emu1010_link_read(emu, buffer, 0x701); 491 } 492 } 493 } 494 495 static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry, 496 struct snd_info_buffer *buffer) 497 { 498 struct snd_emu10k1 *emu = entry->private_data; 499 unsigned long value; 500 int i; 501 snd_iprintf(buffer, "IO Registers:\n\n"); 502 for(i = 0; i < 0x40; i+=4) { 503 value = inl(emu->port + i); 504 snd_iprintf(buffer, "%02X: %08lX\n", i, value); 505 } 506 } 507 508 static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry, 509 struct snd_info_buffer *buffer) 510 { 511 struct snd_emu10k1 *emu = entry->private_data; 512 char line[64]; 513 u32 reg, val; 514 while (!snd_info_get_line(buffer, line, sizeof(line))) { 515 if (sscanf(line, "%x %x", ®, &val) != 2) 516 continue; 517 if (reg < 0x40 && val <= 0xffffffff) { 518 outl(val, emu->port + (reg & 0xfffffffc)); 519 } 520 } 521 } 522 523 static unsigned int snd_ptr_read(struct snd_emu10k1 * emu, 524 unsigned int iobase, 525 unsigned int reg, 526 unsigned int chn) 527 { 528 unsigned long flags; 529 unsigned int regptr, val; 530 531 regptr = (reg << 16) | chn; 532 533 spin_lock_irqsave(&emu->emu_lock, flags); 534 outl(regptr, emu->port + iobase + PTR); 535 val = inl(emu->port + iobase + DATA); 536 spin_unlock_irqrestore(&emu->emu_lock, flags); 537 return val; 538 } 539 540 static void snd_ptr_write(struct snd_emu10k1 *emu, 541 unsigned int iobase, 542 unsigned int reg, 543 unsigned int chn, 544 unsigned int data) 545 { 546 unsigned int regptr; 547 unsigned long flags; 548 549 regptr = (reg << 16) | chn; 550 551 spin_lock_irqsave(&emu->emu_lock, flags); 552 outl(regptr, emu->port + iobase + PTR); 553 outl(data, emu->port + iobase + DATA); 554 spin_unlock_irqrestore(&emu->emu_lock, flags); 555 } 556 557 558 static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry, 559 struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices) 560 { 561 struct snd_emu10k1 *emu = entry->private_data; 562 unsigned long value; 563 int i,j; 564 if (offset+length > 0xa0) { 565 snd_iprintf(buffer, "Input values out of range\n"); 566 return; 567 } 568 snd_iprintf(buffer, "Registers 0x%x\n", iobase); 569 for(i = offset; i < offset+length; i++) { 570 snd_iprintf(buffer, "%02X: ",i); 571 for (j = 0; j < voices; j++) { 572 value = snd_ptr_read(emu, iobase, i, j); 573 snd_iprintf(buffer, "%08lX ", value); 574 } 575 snd_iprintf(buffer, "\n"); 576 } 577 } 578 579 static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry, 580 struct snd_info_buffer *buffer, 581 int iobase, int length, int voices) 582 { 583 struct snd_emu10k1 *emu = entry->private_data; 584 char line[64]; 585 unsigned int reg, channel_id , val; 586 while (!snd_info_get_line(buffer, line, sizeof(line))) { 587 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3) 588 continue; 589 if (reg < length && channel_id < voices) 590 snd_ptr_write(emu, iobase, reg, channel_id, val); 591 } 592 } 593 594 static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry, 595 struct snd_info_buffer *buffer) 596 { 597 snd_emu_proc_ptr_reg_write(entry, buffer, 0, 0x80, 64); 598 } 599 600 static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry, 601 struct snd_info_buffer *buffer) 602 { 603 struct snd_emu10k1 *emu = entry->private_data; 604 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20, 605 emu->card_capabilities->ca0108_chip ? 0xa0 : 0x80, 4); 606 } 607 608 609 static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry, 610 struct snd_info_buffer *buffer) 611 { 612 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64); 613 } 614 615 static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry, 616 struct snd_info_buffer *buffer) 617 { 618 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64); 619 } 620 621 static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry, 622 struct snd_info_buffer *buffer) 623 { 624 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4); 625 } 626 627 static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry, 628 struct snd_info_buffer *buffer) 629 { 630 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4); 631 } 632 633 static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry, 634 struct snd_info_buffer * buffer) 635 { 636 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4); 637 } 638 #endif 639 640 static const struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = { 641 .read = snd_emu10k1_fx8010_read, 642 }; 643 644 int snd_emu10k1_proc_init(struct snd_emu10k1 *emu) 645 { 646 struct snd_info_entry *entry; 647 #ifdef CONFIG_SND_DEBUG 648 if (emu->card_capabilities->emu_model) { 649 snd_card_ro_proc_new(emu->card, "emu1010_regs", 650 emu, snd_emu_proc_emu1010_reg_read); 651 } 652 snd_card_rw_proc_new(emu->card, "io_regs", emu, 653 snd_emu_proc_io_reg_read, 654 snd_emu_proc_io_reg_write); 655 snd_card_rw_proc_new(emu->card, "ptr_regs00a", emu, 656 snd_emu_proc_ptr_reg_read00a, 657 snd_emu_proc_ptr_reg_write00); 658 snd_card_rw_proc_new(emu->card, "ptr_regs00b", emu, 659 snd_emu_proc_ptr_reg_read00b, 660 snd_emu_proc_ptr_reg_write00); 661 if (!emu->card_capabilities->emu_model && 662 (emu->card_capabilities->ca0151_chip || emu->card_capabilities->ca0108_chip)) { 663 snd_card_rw_proc_new(emu->card, "ptr_regs20a", emu, 664 snd_emu_proc_ptr_reg_read20a, 665 snd_emu_proc_ptr_reg_write20); 666 snd_card_rw_proc_new(emu->card, "ptr_regs20b", emu, 667 snd_emu_proc_ptr_reg_read20b, 668 snd_emu_proc_ptr_reg_write20); 669 if (emu->card_capabilities->ca0108_chip) 670 snd_card_rw_proc_new(emu->card, "ptr_regs20c", emu, 671 snd_emu_proc_ptr_reg_read20c, 672 snd_emu_proc_ptr_reg_write20); 673 } 674 #endif 675 676 snd_card_ro_proc_new(emu->card, "emu10k1", emu, snd_emu10k1_proc_read); 677 678 if (emu->card_capabilities->emu10k2_chip) 679 snd_card_ro_proc_new(emu->card, "spdif-in", emu, 680 snd_emu10k1_proc_spdif_read); 681 if (emu->card_capabilities->ca0151_chip) 682 snd_card_ro_proc_new(emu->card, "capture-rates", emu, 683 snd_emu10k1_proc_rates_read); 684 685 snd_card_ro_proc_new(emu->card, "voices", emu, 686 snd_emu10k1_proc_voices_read); 687 688 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) { 689 entry->content = SNDRV_INFO_CONTENT_DATA; 690 entry->private_data = emu; 691 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 692 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR; 693 entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 694 } 695 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) { 696 entry->content = SNDRV_INFO_CONTENT_DATA; 697 entry->private_data = emu; 698 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 699 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ; 700 entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 701 } 702 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) { 703 entry->content = SNDRV_INFO_CONTENT_DATA; 704 entry->private_data = emu; 705 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 706 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ; 707 entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 708 } 709 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) { 710 entry->content = SNDRV_INFO_CONTENT_DATA; 711 entry->private_data = emu; 712 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 713 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE; 714 entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 715 } 716 snd_card_ro_proc_new(emu->card, "fx8010_acode", emu, 717 snd_emu10k1_proc_acode_read); 718 return 0; 719 } 720