#!/usr/bin/python import re import locale import time import sys import os.path CtlMap = { 0x01 : ( 'DAC Control', ('0', '0', 'DACINV', 'DMONOMIX[1:0]', 'DACMU', 'DEEMPH[1:0]', '0', ), 0x008, 'xxx00xxxx' ), 0x02 : ( 'ADC Control', ('DATSEL[1:0]', 'ADCPOL[1:0]', 'VXFILT', 'HPMODE[1:0]', 'HPOR', 'ADCHPD', ), 0x000, '01xx11000' ), 0x03 : ( 'PCM Audio Interface', ('ADCDOP', 'VXCLKIN', 'PMS', 'MONO', 'PLRP', 'PWL[1:0]', 'PFORMAT[1:0]', ), 0x00a, '1xx1xxxxx' ), 0x04 : ( 'Hi-Fi Audio Interface', ('0', 'BCLKINV', 'MS', 'LRSWAP', 'LRP', 'WL[1:0]', 'FORMAT[1:0]', ), 0x00a, 'xxxxxxxxx' ), 0x05 : ( 'Interface Control', ('0', 'VXCLKTRI', 'BCLKTRI', 'VXDTRI', 'ADCDTRI', 'IFMODE[1:0]', 'VXFSOE', 'LRCOE', ), 0x033, 'xxxxxxxxx' ), 0x06 : ( 'Sample Rate Ctrl (1)', ('SRMODE', 'PSR', '0', 'SR[4:0]', 'USB', ), 0x000, 'xxxxxxxxx' ), 0x07 : ( 'Sample Rate Ctrl (2)', ('PBMODE[2:0]', 'BMODE[2:0]', 'VXDOSR', 'ADCOSR', 'DACOSR', ), 0x007, 'xxxxxxxxx' ), 0x08 : ( 'Left DAC volume', ('LDVU', 'LDACVOL[7:0]', ), 0x0ff, 'xxxxxxxxx' ), 0x09 : ( 'Right DAC volume', ('RDVU', 'RDACVOL[7:0]', ), 0x0ff, 'xxxxxxxxx' ), 0x0a : ( 'Bass control', ('0', 'BB', 'BC[2:0]', 'BASS[3:0]', ), 0x00f, 'xxxxxxxxx' ), 0x0b : ( 'Treble control', ('0', '0', 'TC', '0', '0', 'TRBL[3:0]', ), 0x00f, 'xxxxxxxxx' ), 0x0c : ( 'ALC1', ('ALCSEL[1:0]', 'MAXGAIN[2:0]', 'ALCL[3:0]', ), 0x07b, 'xxxxxxxxx' ), 0x0d : ( 'ALC2', ('ALCZC', 'ALCSR[3:0]', 'HLD[3:0]', ), 0x000, 'xxxxxxxxx' ), 0x0e : ( 'ALC3', ('0', 'DCY[3:0]', 'ATK[3:0]', ), 0x032, 'xxxxxxxxx' ), 0x0f : ( 'Noise Gate', ('0', 'NGTH[4:0]', '0', 'NGG', 'NGAT', ), 0x000, 'xxxxxxxxx' ), 0x10 : ( 'Left ADC volume', ('LAVU', 'LADCVOL[7:0]', ), 0x0c3, '1xxxxxxxx' ), 0x11 : ( 'Right ADC volume', ('RAVU', 'RADCVOL[7:0]', ), 0x0c3, '1xxxxxxxx' ), 0x12 : ( 'Additional control', ('0', 'VSEL[1:0]', '0', '0', '0', 'ADCDIV2', 'DACDIV2', 'TOEN', ), 0x0c0, 'xxxxxxxxx' ), 0x13 : ( '3D Control', ('0', 'MODE3D', '3DUC', '3DLC', '3DDEPTH[3:0]', '3DEN', ), 0x000, 'xxxxxxxxx' ), 0x14 : ( 'Pwr Mgmt (1)', ('VMIDSEL[1:0]', 'VREF', 'MICB', 'VDAC', 'DACL', 'DACR', '0', 'DIGENB', ), 0x000, 'xxxxxxxxx' ), 0x15 : ( 'Pwr Mgmt (2)', ('MICAMP1EN', 'MICAMP2E', 'ALCMIX', 'PGAL', 'PGAR', 'ADCL', 'ADCR', 'RXMIX', 'LINEMIX', ), 0x000, 'xxxxxxxxx' ), 0x16 : ( 'Pwr Mgmt (3)', ('LOUT1', 'ROUT1', 'LOUT2', 'ROUT2', 'OUT3', 'OUT4', 'MONO1', 'MONO2', '0', ), 0x000, 'xxxxxxxxx' ), 0x17 : ( 'Pwr Mgmt (4)', ('0', '0', '0', '0', '0', 'RECMIX', 'MONOMIX', 'RIGHTMIX', 'LEFTMIX', ), 0x000, 'xxxxxxxxx' ), 0x18 : ( 'ID register', ('0', '0', '0', '0', 'RDDAT', 'READSEL[2:0]', 'READEN', ), 0x000, 'xxxxxxxxx' ), 0x19 : ( 'Interupt Polarity', ('0', 'TSDIPOL', 'HPSWIPOL', 'GPIO5IPOL', 'GPIO4IPOL', 'GPIO3IPOL', '0', 'MICDETIPOL','MICSHTIPOL',), 0x000, 'xxxxxxxxx' ), 0x1a : ( 'Interupt Enable', ('0', 'TSDIEN', 'HPSWIEN', 'GPIO5IEN', 'GPIO4IEN', 'GPIO3IEN', '0', 'MICDETIEN', 'MICSHTIEN', ), 0x000, 'xxxxxxxxx' ), 0x1b : ( 'GPIO Control (1)', ('INTCON[1:0]', '0', '0', 'GPIO5M[1:0]', 'GPIO4M[2:0]', ), 0x000, 'xxxxxxxxx' ), 0x1c : ( 'GPIO Control (2)', ('GPIO3M[2:0]', 'GP2M[2:0]', 'GP1M[2:0]', ), 0x000, 'xxxxxxxxx' ), 0x1f : ( 'Reset', ('WRITEZEROS[8:0]', ), 0x000, 'xxxxxxxxx' ), 0x20 : ( 'Record Mix (1)', ('0', 'RSEL', 'RRECVOL[2:0]', 'LSEL', 'LRECVOL[2:0]', ), 0x055, 'xxxxxxxxx' ), 0x21 : ( 'Record Mix (2)', ('0', '0', '0', '0', '0', 'MSEL', 'MRECVOL[2:0]', ), 0x005, 'xxxxxxxxx' ), 0x22 : ( 'Left out Mix (1)', ('LD2LO', 'LM2LO', 'LM2LOVOL[2:0]', '0', '0', '0', '0', ), 0x050, 'xxxxxxxxx' ), 0x23 : ( 'Left out Mix (2)', ('VXD2LO', 'ST2LO', 'ST2LOVOL[2:0]', '0', 'VXD2LOVOL[2:0]', ), 0x055, 'xxxxxxxxx' ), 0x24 : ( 'Right out Mix (1)', ('RD2RO', 'RM2RO', 'RM2ROVOL[2:0]', '0', '0', '0', '0', ), 0x050, 'xxxxxxxxx' ), 0x25 : ( 'Right out Mix (2)', ('VXD2RO', 'ST2RO', 'ST2ROVOL[2:0]', '0', 'VXD2ROVOL[2:0]', ), 0x055, 'xxxxxxxxx' ), 0x26 : ( 'Mono out Mix (1)', ('LD2MO', 'MM2MO', 'MM2MOVOL[2:0]', '0', '0', '0', '0', ), 0x050, 'xxxxxxxxx' ), 0x27 : ( 'Mono out Mix (2)', ('RD2MO', 'ST2MO', 'ST2MOVOL[2:0]', 'VXD2MO', 'VXD2MOVOL[2:0]', ), 0x055, 'xxxxxxxxx' ), 0x28 : ( 'LOUT1 volume', ('LO1VU', 'LO1ZC', 'LOUT1VOL[6:0]', ), 0x079, 'xxxxxxxxx' ), 0x29 : ( 'ROUT1 volume', ('RO1VU', 'RO1ZC', 'ROUT1VOL[6:0]', ), 0x079, 'xxxxxxxxx' ), 0x2a : ( 'LOUT2 volume', ('LO2VU', 'LO2ZC', 'LOUT2VOL[6:0]', ), 0x079, 'xxxxxxxxx' ), 0x2b : ( 'ROUT2 volume', ('RO2VU', 'RO2ZC', 'ROUT2VOL[6:0]', ), 0x079, 'xxxxxxxxx' ), 0x2c : ( 'MONOOUT volume', ('0', 'MOZC', 'MONO1VOL[6:0]', ), 0x079, 'xxxxxxxxx' ), 0x2d : ( 'Output Control', ('MONO2SW[1:0]', 'HPSWEN', 'HPSWPO', 'TSDEN', 'VROI', 'ROUT2INV', 'OUT3SW[1:0]', ), 0x000, 'xxxxxxxxx' ), 0x2e : ( 'ADC input mode', ('0', '0', '0', 'MONOMIX[1:0]', 'RADCSEL[1:0]', 'LADCSEL[1:0]', ), 0x000, 'xxxxxxxxx' ), 0x2f : ( 'Input Control (1)', ('MIC2BOOST[1:0]', 'MIC1BOOST[1:0]', 'LMSEL[1:0]', 'MM', 'RM', 'LM', ), 0x000, 'xxxxxxxxx' ), 0x30 : ( 'Input Control (2)', ('0', 'RXMSEL[1:0]', 'MICMUX[1:0]', 'LINEALC', 'MIC2ALC', 'MIC1ALC', 'RXALC', ), 0x000, 'xxxxxxxxx' ), 0x31 : ( 'Left Input volume', ('LIVU', 'LINMUTE', 'LIZC', 'LINVOL[5:0]', ), 0x097, 'xxxxxxxxx' ), 0x32 : ( 'Right Input volume', ('RIVU', 'RINMUTE', 'RIZC', 'RINVOL[5:0]', ), 0x097, 'xxxxxxxxx' ), 0x33 : ( 'Mic Bias comp control', ('MBVSEL', 'MICSEL[1:0]', 'MBSCTHRESH[1:0]', 'MBTHRESH[2:0]', 'MBCEN', ), 0x000, 'xxxxxxxxx' ), 0x34 : ( 'Clock Control', ('PCMDIV[2:0]', 'SLWCLK', 'MCLKSEL', 'PCMCLKSEL', 'CLKEQ', 'GP1CLK1SEL','GP2CLK2SEL',), 0x004, 'xxxxxxxxx' ), 0x35 : ( 'PLL1 Control (1)', ('0', '0', '0', 'CLK1SEL', 'CLK1DIV2', 'MCLK1DIV2', 'PLL1DIV2', 'PLL1RB', 'PLL1EN', ), 0x000, 'xxxxxxxxx' ), 0x36 : ( 'PLL1 Control (2)', ('PLL1N[3:0]', '0', 'PLL1K[21:18]', ), 0x083, 'xxxxxxxxx' ), 0x37 : ( 'PLL1 Control (3)', ('PLL1K[17:9]', ), 0x024, 'xxxxxxxxx' ), 0x38 : ( 'PLL1 Control (4)', ('PLL1K[8:0]', ), 0x1ba, 'xxxxxxxxx' ), 0x39 : ( 'PLL2 Control (1)', ('0', '0', '0', 'CLK2SEL', 'CLK2DIV2', 'MCLK2DIV2', 'PLL2DIV2', 'PLL2RB', 'PLL2EN', ), 0x000, 'xxxxxxxxx' ), 0x3a : ( 'PLL2 Control (2)', ('PLL2N[3:0]', '0', 'PLL2K[21:18]', ), 0x083, 'xxxxxxxxx' ), 0x3b : ( 'PLL2 Control (3)', ('PLL2K[17:9]', ), 0x024, 'xxxxxxxxx' ), 0x3c : ( 'PLL2 Control (4)', ('PLL2K[8:0]', ), 0x1ba, 'xxxxxxxxx' ), 0x3d : ( 'Bias control', ('VDACBIASX0P5','MBIASBOOST','MICBIASBOOST[1:0]', 'BUFBIAS[1:0]', 'IPBIASX0P5','ADCBIAS[1:0]', ), 0x000, 'xxxxxxxxx' ), 0x3f : ( 'Additional Control', ('OUT4SW[1:0]', 'TSADEN', '0', '0', '0', '0', 'OPBIASX0P5','DMBIASX0P5',), 0x000, 'xxxxxxxxx' ), } state_re = re.compile(r'^\s*([0-9a-f]+):\s*([0-9a-f]{1,3})\s*$', re.IGNORECASE) def read_state(filename): state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] statefile = open(filename, mode='r') for line in statefile: linem = state_re.match(line) if linem: reg = int(linem.group(1), 16) val = int(linem.group(2), 16) if val < 512: state[reg] = val statefile.close() return state def waitkey(win): return chr(win.getch()) oldstate = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] for reg in CtlMap: oldstate[reg] = CtlMap[reg][2] curstate = read_state('/sys/bus/platform/devices/soc-audio/codec_reg') maxw = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] width = 0 for reg in CtlMap: for field in CtlMap[reg][1]: hbl = field.find('[') lbl = field.find(':') lbe = field.find(']') if lbe > lbl > hbl > 0: hi=field[hbl+1:lbl] lo=field[lbl+1:lbe] bits=int(hi)-int(lo)+1 else: bits=1 length = len(field) + bits + 1 if length > maxw[bits]: maxw[bits] = length for i in range(1,10): twidth = (maxw[i] - 3 * (i-1)) / i if twidth > width: width = twidth color_odd='\033[0;30;107m' color_even='\033[0;30;47m' color_good='\033[0;39;102m' color_diff='\033[6;39;106m' color_bad='\033[0;39;101m' color_end='\033[0;39;49m' logfile = open(os.path.expandvars('$HOME/w8753reg.log'), 'a') userin = 'Compared to default values:' while userin != 'q\n': print '%s%sT' % ("=" * 28, ('T' + '=' * (width + 2)) * 9) print >>logfile, "\n%s: %s" % (time.asctime(), userin) changed = () for reg in CtlMap: if reg & 1: color_stripe=color_odd else: color_stripe=color_even color_good=color_stripe print '%s0x%02x: %21s' % (color_stripe, reg,CtlMap[reg][0]), bit=8 match = curstate[reg] ^ oldstate[reg] for field in CtlMap[reg][1]: anychange=False hbl = field.find('[') lbl = field.find(':') lbe = field.find(']') if lbe > lbl > hbl > 0: hi=field[hbl+1:lbl] lo=field[lbl+1:lbe] bits=int(hi)-int(lo)+1 else: bits=1 dwidth = len(field) + 1 + bits disp=field+'=' orig=field+'=' for b in range(bits): wantbit = CtlMap[reg][3][8-bit] wantbit = 'x' thisbit = '1' if curstate[reg] & (1 << bit) else '0' obit = '1' if oldstate[reg] & (1 << bit) else '0' if wantbit == 'x' or wantbit == thisbit: if match & (1 << bit): disp += color_diff anychange=True else: disp += color_good else: disp += color_bad orig += str(obit) disp += thisbit disp += color_stripe bit-=1 print "| %s%s%s" % ( " " * int((width * bits + 3*(bits - 1) - dwidth) / 2), disp, " " * int((width * bits + 3*(bits - 1) - dwidth + 1) / 2), ), if anychange: print >>logfile, "Reg. 0x%02x %21s: %s" % (reg, CtlMap[reg][0], orig) print >>logfile, "%33s%s%s" % (' ', disp, color_end) print "%s|" % color_end print "Type a note and hit ENTER to refresh" userin = sys.stdin.readline() oldstate = curstate curstate = read_state('/sys/bus/platform/devices/soc-audio/codec_reg')