1*1a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 21da177e4SLinus Torvalds /* 3c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 41da177e4SLinus Torvalds * Creative Labs, Inc. 51da177e4SLinus Torvalds * Routines for control of EMU10K1 chips / proc interface routines 61da177e4SLinus Torvalds * 79f4bd5ddSJames Courtier-Dutton * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk> 89f4bd5ddSJames Courtier-Dutton * Added EMU 1010 support. 99f4bd5ddSJames Courtier-Dutton * 101da177e4SLinus Torvalds * BUGS: 111da177e4SLinus Torvalds * -- 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * TODO: 141da177e4SLinus Torvalds * -- 151da177e4SLinus Torvalds */ 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #include <linux/slab.h> 181da177e4SLinus Torvalds #include <linux/init.h> 191da177e4SLinus Torvalds #include <sound/core.h> 201da177e4SLinus Torvalds #include <sound/emu10k1.h> 21001f7589SJames Courtier-Dutton #include "p16v.h" 221da177e4SLinus Torvalds 23eb4698f3STakashi Iwai static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu, 24eb4698f3STakashi Iwai struct snd_info_buffer *buffer, 251da177e4SLinus Torvalds char *title, 261da177e4SLinus Torvalds int status_reg, 271da177e4SLinus Torvalds int rate_reg) 281da177e4SLinus Torvalds { 291da177e4SLinus Torvalds static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" }; 301da177e4SLinus Torvalds static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; 311da177e4SLinus Torvalds static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }; 321da177e4SLinus Torvalds static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" }; 331da177e4SLinus Torvalds unsigned int status, rate = 0; 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds status = snd_emu10k1_ptr_read(emu, status_reg, 0); 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds snd_iprintf(buffer, "\n%s\n", title); 381da177e4SLinus Torvalds 39df34140aSJames Courtier-Dutton if (status != 0xffffffff) { 401da177e4SLinus Torvalds snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no"); 411da177e4SLinus Torvalds snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no"); 421da177e4SLinus Torvalds snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no"); 431da177e4SLinus Torvalds snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]); 441da177e4SLinus Torvalds snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6); 451da177e4SLinus Torvalds snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8); 461da177e4SLinus Torvalds snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy"); 471da177e4SLinus Torvalds snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16); 481da177e4SLinus Torvalds snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]); 491da177e4SLinus Torvalds snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]); 501da177e4SLinus Torvalds snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]); 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds if (rate_reg > 0) { 53df34140aSJames Courtier-Dutton rate = snd_emu10k1_ptr_read(emu, rate_reg, 0); 54001f7589SJames Courtier-Dutton snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off"); 551da177e4SLinus Torvalds snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off"); 561da177e4SLinus Torvalds snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off"); 57df34140aSJames Courtier-Dutton /* From ((Rate * 48000 ) / 262144); */ 58df34140aSJames Courtier-Dutton snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11); 591da177e4SLinus Torvalds } 60df34140aSJames Courtier-Dutton } else { 61df34140aSJames Courtier-Dutton snd_iprintf(buffer, "No signal detected.\n"); 62df34140aSJames Courtier-Dutton } 63df34140aSJames Courtier-Dutton 641da177e4SLinus Torvalds } 651da177e4SLinus Torvalds 66eb4698f3STakashi Iwai static void snd_emu10k1_proc_read(struct snd_info_entry *entry, 67eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 681da177e4SLinus Torvalds { 691da177e4SLinus Torvalds /* FIXME - output names are in emufx.c too */ 701da177e4SLinus Torvalds static char *creative_outs[32] = { 711da177e4SLinus Torvalds /* 00 */ "AC97 Left", 721da177e4SLinus Torvalds /* 01 */ "AC97 Right", 731da177e4SLinus Torvalds /* 02 */ "Optical IEC958 Left", 741da177e4SLinus Torvalds /* 03 */ "Optical IEC958 Right", 751da177e4SLinus Torvalds /* 04 */ "Center", 761da177e4SLinus Torvalds /* 05 */ "LFE", 771da177e4SLinus Torvalds /* 06 */ "Headphone Left", 781da177e4SLinus Torvalds /* 07 */ "Headphone Right", 791da177e4SLinus Torvalds /* 08 */ "Surround Left", 801da177e4SLinus Torvalds /* 09 */ "Surround Right", 811da177e4SLinus Torvalds /* 10 */ "PCM Capture Left", 821da177e4SLinus Torvalds /* 11 */ "PCM Capture Right", 831da177e4SLinus Torvalds /* 12 */ "MIC Capture", 841da177e4SLinus Torvalds /* 13 */ "AC97 Surround Left", 851da177e4SLinus Torvalds /* 14 */ "AC97 Surround Right", 861da177e4SLinus Torvalds /* 15 */ "???", 871da177e4SLinus Torvalds /* 16 */ "???", 881da177e4SLinus Torvalds /* 17 */ "Analog Center", 891da177e4SLinus Torvalds /* 18 */ "Analog LFE", 901da177e4SLinus Torvalds /* 19 */ "???", 911da177e4SLinus Torvalds /* 20 */ "???", 921da177e4SLinus Torvalds /* 21 */ "???", 931da177e4SLinus Torvalds /* 22 */ "???", 941da177e4SLinus Torvalds /* 23 */ "???", 951da177e4SLinus Torvalds /* 24 */ "???", 961da177e4SLinus Torvalds /* 25 */ "???", 971da177e4SLinus Torvalds /* 26 */ "???", 981da177e4SLinus Torvalds /* 27 */ "???", 991da177e4SLinus Torvalds /* 28 */ "???", 1001da177e4SLinus Torvalds /* 29 */ "???", 1011da177e4SLinus Torvalds /* 30 */ "???", 1021da177e4SLinus Torvalds /* 31 */ "???" 1031da177e4SLinus Torvalds }; 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds static char *audigy_outs[64] = { 1061da177e4SLinus Torvalds /* 00 */ "Digital Front Left", 1071da177e4SLinus Torvalds /* 01 */ "Digital Front Right", 1081da177e4SLinus Torvalds /* 02 */ "Digital Center", 1091da177e4SLinus Torvalds /* 03 */ "Digital LEF", 1101da177e4SLinus Torvalds /* 04 */ "Headphone Left", 1111da177e4SLinus Torvalds /* 05 */ "Headphone Right", 1121da177e4SLinus Torvalds /* 06 */ "Digital Rear Left", 1131da177e4SLinus Torvalds /* 07 */ "Digital Rear Right", 1141da177e4SLinus Torvalds /* 08 */ "Front Left", 1151da177e4SLinus Torvalds /* 09 */ "Front Right", 1161da177e4SLinus Torvalds /* 10 */ "Center", 1171da177e4SLinus Torvalds /* 11 */ "LFE", 1181da177e4SLinus Torvalds /* 12 */ "???", 1191da177e4SLinus Torvalds /* 13 */ "???", 1201da177e4SLinus Torvalds /* 14 */ "Rear Left", 1211da177e4SLinus Torvalds /* 15 */ "Rear Right", 1221da177e4SLinus Torvalds /* 16 */ "AC97 Front Left", 1231da177e4SLinus Torvalds /* 17 */ "AC97 Front Right", 124bf8b47feSColin Ian King /* 18 */ "ADC Capture Left", 1251da177e4SLinus Torvalds /* 19 */ "ADC Capture Right", 1261da177e4SLinus Torvalds /* 20 */ "???", 1271da177e4SLinus Torvalds /* 21 */ "???", 1281da177e4SLinus Torvalds /* 22 */ "???", 1291da177e4SLinus Torvalds /* 23 */ "???", 1301da177e4SLinus Torvalds /* 24 */ "???", 1311da177e4SLinus Torvalds /* 25 */ "???", 1321da177e4SLinus Torvalds /* 26 */ "???", 1331da177e4SLinus Torvalds /* 27 */ "???", 1341da177e4SLinus Torvalds /* 28 */ "???", 1351da177e4SLinus Torvalds /* 29 */ "???", 1361da177e4SLinus Torvalds /* 30 */ "???", 1371da177e4SLinus Torvalds /* 31 */ "???", 1381da177e4SLinus Torvalds /* 32 */ "FXBUS2_0", 1391da177e4SLinus Torvalds /* 33 */ "FXBUS2_1", 1401da177e4SLinus Torvalds /* 34 */ "FXBUS2_2", 1411da177e4SLinus Torvalds /* 35 */ "FXBUS2_3", 1421da177e4SLinus Torvalds /* 36 */ "FXBUS2_4", 1431da177e4SLinus Torvalds /* 37 */ "FXBUS2_5", 1441da177e4SLinus Torvalds /* 38 */ "FXBUS2_6", 1451da177e4SLinus Torvalds /* 39 */ "FXBUS2_7", 1461da177e4SLinus Torvalds /* 40 */ "FXBUS2_8", 1471da177e4SLinus Torvalds /* 41 */ "FXBUS2_9", 1481da177e4SLinus Torvalds /* 42 */ "FXBUS2_10", 1491da177e4SLinus Torvalds /* 43 */ "FXBUS2_11", 1501da177e4SLinus Torvalds /* 44 */ "FXBUS2_12", 1511da177e4SLinus Torvalds /* 45 */ "FXBUS2_13", 1521da177e4SLinus Torvalds /* 46 */ "FXBUS2_14", 1531da177e4SLinus Torvalds /* 47 */ "FXBUS2_15", 1541da177e4SLinus Torvalds /* 48 */ "FXBUS2_16", 1551da177e4SLinus Torvalds /* 49 */ "FXBUS2_17", 1561da177e4SLinus Torvalds /* 50 */ "FXBUS2_18", 1571da177e4SLinus Torvalds /* 51 */ "FXBUS2_19", 1581da177e4SLinus Torvalds /* 52 */ "FXBUS2_20", 1591da177e4SLinus Torvalds /* 53 */ "FXBUS2_21", 1601da177e4SLinus Torvalds /* 54 */ "FXBUS2_22", 1611da177e4SLinus Torvalds /* 55 */ "FXBUS2_23", 1621da177e4SLinus Torvalds /* 56 */ "FXBUS2_24", 1631da177e4SLinus Torvalds /* 57 */ "FXBUS2_25", 1641da177e4SLinus Torvalds /* 58 */ "FXBUS2_26", 1651da177e4SLinus Torvalds /* 59 */ "FXBUS2_27", 1661da177e4SLinus Torvalds /* 60 */ "FXBUS2_28", 1671da177e4SLinus Torvalds /* 61 */ "FXBUS2_29", 1681da177e4SLinus Torvalds /* 62 */ "FXBUS2_30", 1691da177e4SLinus Torvalds /* 63 */ "FXBUS2_31" 1701da177e4SLinus Torvalds }; 1711da177e4SLinus Torvalds 172eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 1731da177e4SLinus Torvalds unsigned int val, val1; 1741da177e4SLinus Torvalds int nefx = emu->audigy ? 64 : 32; 1751da177e4SLinus Torvalds char **outputs = emu->audigy ? audigy_outs : creative_outs; 1761da177e4SLinus Torvalds int idx; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds snd_iprintf(buffer, "EMU10K1\n\n"); 1791da177e4SLinus Torvalds snd_iprintf(buffer, "Card : %s\n", 1802b637da5SLee Revell emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative")); 1811da177e4SLinus Torvalds snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size); 1821da177e4SLinus Torvalds snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2); 1831da177e4SLinus Torvalds snd_iprintf(buffer, "\n"); 1841da177e4SLinus Torvalds snd_iprintf(buffer, "Effect Send Routing :\n"); 1851da177e4SLinus Torvalds for (idx = 0; idx < NUM_G; idx++) { 1861da177e4SLinus Torvalds val = emu->audigy ? 1871da177e4SLinus Torvalds snd_emu10k1_ptr_read(emu, A_FXRT1, idx) : 1881da177e4SLinus Torvalds snd_emu10k1_ptr_read(emu, FXRT, idx); 1891da177e4SLinus Torvalds val1 = emu->audigy ? 1901da177e4SLinus Torvalds snd_emu10k1_ptr_read(emu, A_FXRT2, idx) : 1911da177e4SLinus Torvalds 0; 1921da177e4SLinus Torvalds if (emu->audigy) { 1931da177e4SLinus Torvalds snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ", 1941da177e4SLinus Torvalds idx, 1951da177e4SLinus Torvalds val & 0x3f, 1961da177e4SLinus Torvalds (val >> 8) & 0x3f, 1971da177e4SLinus Torvalds (val >> 16) & 0x3f, 1981da177e4SLinus Torvalds (val >> 24) & 0x3f); 1991da177e4SLinus Torvalds snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n", 2001da177e4SLinus Torvalds val1 & 0x3f, 2011da177e4SLinus Torvalds (val1 >> 8) & 0x3f, 2021da177e4SLinus Torvalds (val1 >> 16) & 0x3f, 2031da177e4SLinus Torvalds (val1 >> 24) & 0x3f); 2041da177e4SLinus Torvalds } else { 2051da177e4SLinus Torvalds snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n", 2061da177e4SLinus Torvalds idx, 2071da177e4SLinus Torvalds (val >> 16) & 0x0f, 2081da177e4SLinus Torvalds (val >> 20) & 0x0f, 2091da177e4SLinus Torvalds (val >> 24) & 0x0f, 2101da177e4SLinus Torvalds (val >> 28) & 0x0f); 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds } 2131da177e4SLinus Torvalds snd_iprintf(buffer, "\nCaptured FX Outputs :\n"); 2141da177e4SLinus Torvalds for (idx = 0; idx < nefx; idx++) { 2151da177e4SLinus Torvalds if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) 2161da177e4SLinus Torvalds snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]); 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds snd_iprintf(buffer, "\nAll FX Outputs :\n"); 2191da177e4SLinus Torvalds for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++) 2201da177e4SLinus Torvalds snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]); 221df34140aSJames Courtier-Dutton } 222df34140aSJames Courtier-Dutton 223eb4698f3STakashi Iwai static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, 224eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 225df34140aSJames Courtier-Dutton { 226eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 227f93abe51SJames Courtier-Dutton u32 value; 228f93abe51SJames Courtier-Dutton u32 value2; 229f93abe51SJames Courtier-Dutton u32 rate; 230f93abe51SJames Courtier-Dutton 231190d2c46SJames Courtier-Dutton if (emu->card_capabilities->emu_model) { 232f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x38, &value); 233f93abe51SJames Courtier-Dutton if ((value & 0x1) == 0) { 234f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x2a, &value); 235f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x2b, &value2); 236f93abe51SJames Courtier-Dutton rate = 0x1770000 / (((value << 5) | value2)+1); 237f93abe51SJames Courtier-Dutton snd_iprintf(buffer, "ADAT Locked : %u\n", rate); 238f93abe51SJames Courtier-Dutton } else { 239f93abe51SJames Courtier-Dutton snd_iprintf(buffer, "ADAT Unlocked\n"); 240f93abe51SJames Courtier-Dutton } 241f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x20, &value); 242f93abe51SJames Courtier-Dutton if ((value & 0x4) == 0) { 243f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x28, &value); 244f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, 0x29, &value2); 245f93abe51SJames Courtier-Dutton rate = 0x1770000 / (((value << 5) | value2)+1); 246f93abe51SJames Courtier-Dutton snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); 247f93abe51SJames Courtier-Dutton } else { 248f93abe51SJames Courtier-Dutton snd_iprintf(buffer, "SPDIF Unlocked\n"); 249f93abe51SJames Courtier-Dutton } 250f93abe51SJames Courtier-Dutton } else { 251df34140aSJames Courtier-Dutton snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS); 252df34140aSJames Courtier-Dutton snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS); 253f93abe51SJames Courtier-Dutton } 254df34140aSJames Courtier-Dutton #if 0 2551da177e4SLinus Torvalds val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0); 2561da177e4SLinus Torvalds snd_iprintf(buffer, "\nZoomed Video\n"); 2571da177e4SLinus Torvalds snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off"); 2581da177e4SLinus Torvalds snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE); 259df34140aSJames Courtier-Dutton #endif 2601da177e4SLinus Torvalds } 2611da177e4SLinus Torvalds 262eb4698f3STakashi Iwai static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry, 263eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 264001f7589SJames Courtier-Dutton { 265001f7589SJames Courtier-Dutton static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 }; 266eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 267001f7589SJames Courtier-Dutton unsigned int val, tmp, n; 268001f7589SJames Courtier-Dutton val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0); 269001f7589SJames Courtier-Dutton for (n = 0; n < 4; n++) { 270001f7589SJames Courtier-Dutton tmp = val >> (16 + (n*4)); 271001f7589SJames Courtier-Dutton if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]); 272001f7589SJames Courtier-Dutton else snd_iprintf(buffer, "Channel %d: No input\n", n); 273001f7589SJames Courtier-Dutton } 274001f7589SJames Courtier-Dutton } 275001f7589SJames Courtier-Dutton 276eb4698f3STakashi Iwai static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry, 277eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 2781da177e4SLinus Torvalds { 2791da177e4SLinus Torvalds u32 pc; 280eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name); 2831da177e4SLinus Torvalds snd_iprintf(buffer, " Code dump :\n"); 2841da177e4SLinus Torvalds for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) { 2851da177e4SLinus Torvalds u32 low, high; 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds low = snd_emu10k1_efx_read(emu, pc * 2); 2881da177e4SLinus Torvalds high = snd_emu10k1_efx_read(emu, pc * 2 + 1); 2891da177e4SLinus Torvalds if (emu->audigy) 2901da177e4SLinus Torvalds snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n", 2911da177e4SLinus Torvalds (high >> 24) & 0x0f, 2921da177e4SLinus Torvalds (high >> 12) & 0x7ff, 2931da177e4SLinus Torvalds (high >> 0) & 0x7ff, 2941da177e4SLinus Torvalds (low >> 12) & 0x7ff, 2951da177e4SLinus Torvalds (low >> 0) & 0x7ff, 2961da177e4SLinus Torvalds pc, 2971da177e4SLinus Torvalds high, low); 2981da177e4SLinus Torvalds else 2991da177e4SLinus Torvalds snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n", 3001da177e4SLinus Torvalds (high >> 20) & 0x0f, 3011da177e4SLinus Torvalds (high >> 10) & 0x3ff, 3021da177e4SLinus Torvalds (high >> 0) & 0x3ff, 3031da177e4SLinus Torvalds (low >> 10) & 0x3ff, 3041da177e4SLinus Torvalds (low >> 0) & 0x3ff, 3051da177e4SLinus Torvalds pc, 3061da177e4SLinus Torvalds high, low); 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds #define TOTAL_SIZE_GPR (0x100*4) 3111da177e4SLinus Torvalds #define A_TOTAL_SIZE_GPR (0x200*4) 3121da177e4SLinus Torvalds #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4) 3131da177e4SLinus Torvalds #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4) 3141da177e4SLinus Torvalds #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4) 3151da177e4SLinus Torvalds #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4) 3161da177e4SLinus Torvalds #define TOTAL_SIZE_CODE (0x200*8) 3171da177e4SLinus Torvalds #define A_TOTAL_SIZE_CODE (0x400*8) 3181da177e4SLinus Torvalds 31924e4a121STakashi Iwai static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry, 320eb4698f3STakashi Iwai void *file_private_data, 3211da177e4SLinus Torvalds struct file *file, char __user *buf, 32224e4a121STakashi Iwai size_t count, loff_t pos) 3231da177e4SLinus Torvalds { 324eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 3251da177e4SLinus Torvalds unsigned int offset; 3261da177e4SLinus Torvalds int tram_addr = 0; 327d97e1b78STakashi Iwai unsigned int *tmp; 328d97e1b78STakashi Iwai long res; 329d97e1b78STakashi Iwai unsigned int idx; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds if (!strcmp(entry->name, "fx8010_tram_addr")) { 3321da177e4SLinus Torvalds offset = TANKMEMADDRREGBASE; 3331da177e4SLinus Torvalds tram_addr = 1; 3341da177e4SLinus Torvalds } else if (!strcmp(entry->name, "fx8010_tram_data")) { 3351da177e4SLinus Torvalds offset = TANKMEMDATAREGBASE; 3361da177e4SLinus Torvalds } else if (!strcmp(entry->name, "fx8010_code")) { 3371da177e4SLinus Torvalds offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE; 3381da177e4SLinus Torvalds } else { 3391da177e4SLinus Torvalds offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE; 3401da177e4SLinus Torvalds } 341d97e1b78STakashi Iwai 342d97e1b78STakashi Iwai tmp = kmalloc(count + 8, GFP_KERNEL); 343d97e1b78STakashi Iwai if (!tmp) 3441da177e4SLinus Torvalds return -ENOMEM; 345d97e1b78STakashi Iwai for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) { 346d97e1b78STakashi Iwai unsigned int val; 347d97e1b78STakashi Iwai val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0); 3481da177e4SLinus Torvalds if (tram_addr && emu->audigy) { 349d97e1b78STakashi Iwai val >>= 11; 350d97e1b78STakashi Iwai val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20; 3511da177e4SLinus Torvalds } 352d97e1b78STakashi Iwai tmp[idx] = val; 353d97e1b78STakashi Iwai } 354d97e1b78STakashi Iwai if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count)) 355d97e1b78STakashi Iwai res = -EFAULT; 356d97e1b78STakashi Iwai else 357d97e1b78STakashi Iwai res = count; 3581da177e4SLinus Torvalds kfree(tmp); 3591da177e4SLinus Torvalds return res; 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds 362eb4698f3STakashi Iwai static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry, 363eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 3641da177e4SLinus Torvalds { 365eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 366eb4698f3STakashi Iwai struct snd_emu10k1_voice *voice; 3671da177e4SLinus Torvalds int idx; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n"); 3701da177e4SLinus Torvalds for (idx = 0; idx < NUM_G; idx++) { 3711da177e4SLinus Torvalds voice = &emu->voices[idx]; 3721da177e4SLinus Torvalds snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n", 3731da177e4SLinus Torvalds idx, 3741da177e4SLinus Torvalds voice->use, 3751da177e4SLinus Torvalds voice->pcm, 3761da177e4SLinus Torvalds voice->efx, 3771da177e4SLinus Torvalds voice->synth, 3781da177e4SLinus Torvalds voice->midi); 3791da177e4SLinus Torvalds } 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG 3839f4bd5ddSJames Courtier-Dutton static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, 3849f4bd5ddSJames Courtier-Dutton struct snd_info_buffer *buffer) 3859f4bd5ddSJames Courtier-Dutton { 3869f4bd5ddSJames Courtier-Dutton struct snd_emu10k1 *emu = entry->private_data; 3874677df07SHarvey Harrison u32 value; 3889f4bd5ddSJames Courtier-Dutton int i; 3899f4bd5ddSJames Courtier-Dutton snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 3909f4bd5ddSJames Courtier-Dutton 39190fd5ce5SJames Courtier-Dutton for(i = 0; i < 0x40; i+=1) { 392f93abe51SJames Courtier-Dutton snd_emu1010_fpga_read(emu, i, &value); 393f93abe51SJames Courtier-Dutton snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f); 3949f4bd5ddSJames Courtier-Dutton } 3959f4bd5ddSJames Courtier-Dutton } 3969f4bd5ddSJames Courtier-Dutton 397eb4698f3STakashi Iwai static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry, 398eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 3991da177e4SLinus Torvalds { 400eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 4011da177e4SLinus Torvalds unsigned long value; 4021da177e4SLinus Torvalds unsigned long flags; 4031da177e4SLinus Torvalds int i; 4041da177e4SLinus Torvalds snd_iprintf(buffer, "IO Registers:\n\n"); 4051da177e4SLinus Torvalds for(i = 0; i < 0x40; i+=4) { 4061da177e4SLinus Torvalds spin_lock_irqsave(&emu->emu_lock, flags); 4071da177e4SLinus Torvalds value = inl(emu->port + i); 4081da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->emu_lock, flags); 4091da177e4SLinus Torvalds snd_iprintf(buffer, "%02X: %08lX\n", i, value); 4101da177e4SLinus Torvalds } 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds 413eb4698f3STakashi Iwai static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry, 414eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 4151da177e4SLinus Torvalds { 416eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 4171da177e4SLinus Torvalds unsigned long flags; 4181da177e4SLinus Torvalds char line[64]; 4191da177e4SLinus Torvalds u32 reg, val; 4201da177e4SLinus Torvalds while (!snd_info_get_line(buffer, line, sizeof(line))) { 4211da177e4SLinus Torvalds if (sscanf(line, "%x %x", ®, &val) != 2) 4221da177e4SLinus Torvalds continue; 42384ed1a19SRoel Kluin if (reg < 0x40 && val <= 0xffffffff) { 4241da177e4SLinus Torvalds spin_lock_irqsave(&emu->emu_lock, flags); 4251da177e4SLinus Torvalds outl(val, emu->port + (reg & 0xfffffffc)); 4261da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->emu_lock, flags); 4271da177e4SLinus Torvalds } 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds 431eb4698f3STakashi Iwai static unsigned int snd_ptr_read(struct snd_emu10k1 * emu, 4321da177e4SLinus Torvalds unsigned int iobase, 4331da177e4SLinus Torvalds unsigned int reg, 4341da177e4SLinus Torvalds unsigned int chn) 4351da177e4SLinus Torvalds { 4361da177e4SLinus Torvalds unsigned long flags; 4371da177e4SLinus Torvalds unsigned int regptr, val; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds regptr = (reg << 16) | chn; 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds spin_lock_irqsave(&emu->emu_lock, flags); 4421da177e4SLinus Torvalds outl(regptr, emu->port + iobase + PTR); 4431da177e4SLinus Torvalds val = inl(emu->port + iobase + DATA); 4441da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->emu_lock, flags); 4451da177e4SLinus Torvalds return val; 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds 448eb4698f3STakashi Iwai static void snd_ptr_write(struct snd_emu10k1 *emu, 4491da177e4SLinus Torvalds unsigned int iobase, 4501da177e4SLinus Torvalds unsigned int reg, 4511da177e4SLinus Torvalds unsigned int chn, 4521da177e4SLinus Torvalds unsigned int data) 4531da177e4SLinus Torvalds { 4541da177e4SLinus Torvalds unsigned int regptr; 4551da177e4SLinus Torvalds unsigned long flags; 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds regptr = (reg << 16) | chn; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds spin_lock_irqsave(&emu->emu_lock, flags); 4601da177e4SLinus Torvalds outl(regptr, emu->port + iobase + PTR); 4611da177e4SLinus Torvalds outl(data, emu->port + iobase + DATA); 4621da177e4SLinus Torvalds spin_unlock_irqrestore(&emu->emu_lock, flags); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds 466eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry, 467eb4698f3STakashi Iwai struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices) 4681da177e4SLinus Torvalds { 469eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 4701da177e4SLinus Torvalds unsigned long value; 4711da177e4SLinus Torvalds int i,j; 4726ef7e861SJames Courtier-Dutton if (offset+length > 0xa0) { 4731da177e4SLinus Torvalds snd_iprintf(buffer, "Input values out of range\n"); 4741da177e4SLinus Torvalds return; 4751da177e4SLinus Torvalds } 4761da177e4SLinus Torvalds snd_iprintf(buffer, "Registers 0x%x\n", iobase); 4771da177e4SLinus Torvalds for(i = offset; i < offset+length; i++) { 4781da177e4SLinus Torvalds snd_iprintf(buffer, "%02X: ",i); 4791da177e4SLinus Torvalds for (j = 0; j < voices; j++) { 4801da177e4SLinus Torvalds if(iobase == 0) 4811da177e4SLinus Torvalds value = snd_ptr_read(emu, 0, i, j); 4821da177e4SLinus Torvalds else 4831da177e4SLinus Torvalds value = snd_ptr_read(emu, 0x20, i, j); 4841da177e4SLinus Torvalds snd_iprintf(buffer, "%08lX ", value); 4851da177e4SLinus Torvalds } 4861da177e4SLinus Torvalds snd_iprintf(buffer, "\n"); 4871da177e4SLinus Torvalds } 4881da177e4SLinus Torvalds } 4891da177e4SLinus Torvalds 490eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry, 491eb4698f3STakashi Iwai struct snd_info_buffer *buffer, int iobase) 4921da177e4SLinus Torvalds { 493eb4698f3STakashi Iwai struct snd_emu10k1 *emu = entry->private_data; 4941da177e4SLinus Torvalds char line[64]; 4951da177e4SLinus Torvalds unsigned int reg, channel_id , val; 4961da177e4SLinus Torvalds while (!snd_info_get_line(buffer, line, sizeof(line))) { 4971da177e4SLinus Torvalds if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3) 4981da177e4SLinus Torvalds continue; 49984ed1a19SRoel Kluin if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3) 5001da177e4SLinus Torvalds snd_ptr_write(emu, iobase, reg, channel_id, val); 5011da177e4SLinus Torvalds } 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds 504eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry, 505eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5061da177e4SLinus Torvalds { 5071da177e4SLinus Torvalds snd_emu_proc_ptr_reg_write(entry, buffer, 0); 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds 510eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry, 511eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5121da177e4SLinus Torvalds { 5131da177e4SLinus Torvalds snd_emu_proc_ptr_reg_write(entry, buffer, 0x20); 5141da177e4SLinus Torvalds } 5151da177e4SLinus Torvalds 5161da177e4SLinus Torvalds 517eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry, 518eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5191da177e4SLinus Torvalds { 5201da177e4SLinus Torvalds snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64); 5211da177e4SLinus Torvalds } 5221da177e4SLinus Torvalds 523eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry, 524eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5251da177e4SLinus Torvalds { 5261da177e4SLinus Torvalds snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64); 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds 529eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry, 530eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5311da177e4SLinus Torvalds { 5321da177e4SLinus Torvalds snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4); 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds 535eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry, 536eb4698f3STakashi Iwai struct snd_info_buffer *buffer) 5371da177e4SLinus Torvalds { 5381da177e4SLinus Torvalds snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4); 5391da177e4SLinus Torvalds } 5406ef7e861SJames Courtier-Dutton 541eb4698f3STakashi Iwai static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry, 542eb4698f3STakashi Iwai struct snd_info_buffer * buffer) 5436ef7e861SJames Courtier-Dutton { 5446ef7e861SJames Courtier-Dutton snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4); 5456ef7e861SJames Courtier-Dutton } 5461da177e4SLinus Torvalds #endif 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = { 5491da177e4SLinus Torvalds .read = snd_emu10k1_fx8010_read, 5501da177e4SLinus Torvalds }; 5511da177e4SLinus Torvalds 552e23e7a14SBill Pemberton int snd_emu10k1_proc_init(struct snd_emu10k1 *emu) 5531da177e4SLinus Torvalds { 554eb4698f3STakashi Iwai struct snd_info_entry *entry; 5551da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG 556190d2c46SJames Courtier-Dutton if (emu->card_capabilities->emu_model) { 55747f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "emu1010_regs", 55847f2769bSTakashi Iwai emu, snd_emu_proc_emu1010_reg_read); 5599f4bd5ddSJames Courtier-Dutton } 56047f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "io_regs", emu, 56147f2769bSTakashi Iwai snd_emu_proc_io_reg_read, 56247f2769bSTakashi Iwai snd_emu_proc_io_reg_write); 56347f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "ptr_regs00a", emu, 56447f2769bSTakashi Iwai snd_emu_proc_ptr_reg_read00a, 56547f2769bSTakashi Iwai snd_emu_proc_ptr_reg_write00); 56647f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "ptr_regs00b", emu, 56747f2769bSTakashi Iwai snd_emu_proc_ptr_reg_read00b, 56847f2769bSTakashi Iwai snd_emu_proc_ptr_reg_write00); 56947f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "ptr_regs20a", emu, 57047f2769bSTakashi Iwai snd_emu_proc_ptr_reg_read20a, 57147f2769bSTakashi Iwai snd_emu_proc_ptr_reg_write20); 57247f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "ptr_regs20b", emu, 57347f2769bSTakashi Iwai snd_emu_proc_ptr_reg_read20b, 57447f2769bSTakashi Iwai snd_emu_proc_ptr_reg_write20); 57547f2769bSTakashi Iwai snd_card_rw_proc_new(emu->card, "ptr_regs20c", emu, 57647f2769bSTakashi Iwai snd_emu_proc_ptr_reg_read20c, 57747f2769bSTakashi Iwai snd_emu_proc_ptr_reg_write20); 5781da177e4SLinus Torvalds #endif 5791da177e4SLinus Torvalds 58047f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "emu10k1", emu, snd_emu10k1_proc_read); 5811da177e4SLinus Torvalds 58247f2769bSTakashi Iwai if (emu->card_capabilities->emu10k2_chip) 58347f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "spdif-in", emu, 58447f2769bSTakashi Iwai snd_emu10k1_proc_spdif_read); 58547f2769bSTakashi Iwai if (emu->card_capabilities->ca0151_chip) 58647f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "capture-rates", emu, 58747f2769bSTakashi Iwai snd_emu10k1_proc_rates_read); 588df34140aSJames Courtier-Dutton 58947f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "voices", emu, 59047f2769bSTakashi Iwai snd_emu10k1_proc_voices_read); 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) { 5931da177e4SLinus Torvalds entry->content = SNDRV_INFO_CONTENT_DATA; 5941da177e4SLinus Torvalds entry->private_data = emu; 5956a73cf46SJoe Perches entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 5961da177e4SLinus Torvalds entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR; 5971da177e4SLinus Torvalds entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 5981da177e4SLinus Torvalds } 5991da177e4SLinus Torvalds if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) { 6001da177e4SLinus Torvalds entry->content = SNDRV_INFO_CONTENT_DATA; 6011da177e4SLinus Torvalds entry->private_data = emu; 6026a73cf46SJoe Perches entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 6031da177e4SLinus Torvalds entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ; 6041da177e4SLinus Torvalds entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 6051da177e4SLinus Torvalds } 6061da177e4SLinus Torvalds if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) { 6071da177e4SLinus Torvalds entry->content = SNDRV_INFO_CONTENT_DATA; 6081da177e4SLinus Torvalds entry->private_data = emu; 6096a73cf46SJoe Perches entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 6101da177e4SLinus Torvalds entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ; 6111da177e4SLinus Torvalds entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 6121da177e4SLinus Torvalds } 6131da177e4SLinus Torvalds if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) { 6141da177e4SLinus Torvalds entry->content = SNDRV_INFO_CONTENT_DATA; 6151da177e4SLinus Torvalds entry->private_data = emu; 6166a73cf46SJoe Perches entry->mode = S_IFREG | 0444 /*| S_IWUSR*/; 6171da177e4SLinus Torvalds entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE; 6181da177e4SLinus Torvalds entry->c.ops = &snd_emu10k1_proc_ops_fx8010; 6191da177e4SLinus Torvalds } 62047f2769bSTakashi Iwai snd_card_ro_proc_new(emu->card, "fx8010_acode", emu, 62147f2769bSTakashi Iwai snd_emu10k1_proc_acode_read); 6221da177e4SLinus Torvalds return 0; 6231da177e4SLinus Torvalds } 624