diff options
-rw-r--r-- | firmware/drivers/audio/wm8978.c | 66 | ||||
-rw-r--r-- | firmware/export/wm8978.h | 91 |
2 files changed, 56 insertions, 101 deletions
diff --git a/firmware/drivers/audio/wm8978.c b/firmware/drivers/audio/wm8978.c index e93c33b5ec..a2dbf5a8fb 100644 --- a/firmware/drivers/audio/wm8978.c +++ b/firmware/drivers/audio/wm8978.c @@ -76,11 +76,11 @@ static uint16_t wmc_regs[WMC_NUM_REGISTERS] = [WMC_GPIO] = 0x000, [WMC_JACK_DETECT_CONTROL1] = 0x000, [WMC_DAC_CONTROL] = 0x000, - [WMC_LEFT_DAC_DIGITAL_VOL] = 0x0ff | WMC_VU, + [WMC_LEFT_DAC_DIGITAL_VOL] = 0x0ff, /* Latch left first */ [WMC_RIGHT_DAC_DIGITAL_VOL] = 0x0ff | WMC_VU, [WMC_JACK_DETECT_CONTROL2] = 0x000, [WMC_ADC_CONTROL] = 0x100, - [WMC_LEFT_ADC_DIGITAL_VOL] = 0x0ff | WMC_VU, + [WMC_LEFT_ADC_DIGITAL_VOL] = 0x0ff, /* Latch left first */ [WMC_RIGHT_ADC_DIGITAL_VOL] = 0x0ff | WMC_VU, [WMC_EQ1_LOW_SHELF] = 0x12c, [WMC_EQ2_PEAK1] = 0x02c, @@ -104,16 +104,16 @@ static uint16_t wmc_regs[WMC_NUM_REGISTERS] = [WMC_3D_CONTROL] = 0x000, [WMC_BEEP_CONTROL] = 0x000, [WMC_INPUT_CTRL] = 0x033, - [WMC_LEFT_INP_PGA_GAIN_CTRL] = 0x010 | WMC_VU | WMC_ZC, + [WMC_LEFT_INP_PGA_GAIN_CTRL] = 0x010 | WMC_ZC, /* Latch left first */ [WMC_RIGHT_INP_PGA_GAIN_CTRL] = 0x010 | WMC_VU | WMC_ZC, [WMC_LEFT_ADC_BOOST_CTRL] = 0x100, [WMC_RIGHT_ADC_BOOST_CTRL] = 0x100, [WMC_OUTPUT_CTRL] = 0x002, [WMC_LEFT_MIXER_CTRL] = 0x001, [WMC_RIGHT_MIXER_CTRL] = 0x001, - [WMC_LOUT1_HP_VOLUME_CTRL] = 0x039 | WMC_VU | WMC_ZC, + [WMC_LOUT1_HP_VOLUME_CTRL] = 0x039 | WMC_ZC, /* Latch left first */ [WMC_ROUT1_HP_VOLUME_CTRL] = 0x039 | WMC_VU | WMC_ZC, - [WMC_LOUT2_SPK_VOLUME_CTRL] = 0x039 | WMC_VU | WMC_ZC, + [WMC_LOUT2_SPK_VOLUME_CTRL] = 0x039 | WMC_ZC, /* Latch left first */ [WMC_ROUT2_SPK_VOLUME_CTRL] = 0x039 | WMC_VU | WMC_ZC, [WMC_OUT3_MIXER_CTRL] = 0x001, [WMC_OUT4_MONO_MIXER_CTRL] = 0x001, @@ -305,17 +305,17 @@ void audiohw_set_headphone_vol(int vol_l, int vol_r) get_headphone_levels(vol_l, &dac_l, &hp_l, &mix_l, &boost_l); get_headphone_levels(vol_r, &dac_r, &hp_r, &mix_r, &boost_r); - wmc_write_masked(WMC_LEFT_MIXER_CTRL, WMC_BYPLMIXVOLw(mix_l), + wmc_write_masked(WMC_LEFT_MIXER_CTRL, mix_l << WMC_BYPLMIXVOL_POS, WMC_BYPLMIXVOL); wmc_write_masked(WMC_LEFT_ADC_BOOST_CTRL, - WMC_L2_2BOOSTVOLw(boost_l), WMC_L2_2BOOSTVOL); + boost_l << WMC_L2_2BOOSTVOL_POS, WMC_L2_2BOOSTVOL); wmc_write_masked(WMC_LEFT_DAC_DIGITAL_VOL, dac_l, WMC_DVOL); wmc_write_masked(WMC_LOUT1_HP_VOLUME_CTRL, hp_l, WMC_AVOL); - wmc_write_masked(WMC_RIGHT_MIXER_CTRL, WMC_BYPRMIXVOLw(mix_r), + wmc_write_masked(WMC_RIGHT_MIXER_CTRL, mix_r << WMC_BYPRMIXVOL_POS, WMC_BYPRMIXVOL); wmc_write_masked(WMC_RIGHT_ADC_BOOST_CTRL, - WMC_R2_2BOOSTVOLw(boost_r), WMC_R2_2BOOSTVOL); + boost_r << WMC_R2_2BOOSTVOL_POS, WMC_R2_2BOOSTVOL); wmc_write_masked(WMC_RIGHT_DAC_DIGITAL_VOL, dac_r, WMC_DVOL); wmc_write_masked(WMC_ROUT1_HP_VOLUME_CTRL, hp_r, WMC_AVOL); @@ -400,10 +400,10 @@ void audiohw_set_frequency(int fsel) { [HW_FREQ_8] = /* PLL = 65.536MHz */ { - .plln = WMC_PLLNw(7) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(12414886ul >> 18), - .pllk2 = WMC_PLLK_17_9w(12414886ul >> 9), - .pllk3 = WMC_PLLK_8_0w(12414886ul >> 0), + .plln = 7 | WMC_PLL_PRESCALE, + .pllk1 = 0x2f, /* 12414886 */ + .pllk2 = 0x0b7, + .pllk3 = 0x1a6, .mclkdiv = WMC_MCLKDIV_8, /* 2.0480 MHz */ .filter = WMC_SR_8KHZ, }, @@ -414,19 +414,19 @@ void audiohw_set_frequency(int fsel) }, [HW_FREQ_12] = /* PLL = 73.728 MHz */ { - .plln = WMC_PLLNw(8) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(11869595ul >> 18), - .pllk2 = WMC_PLLK_17_9w(11869595ul >> 9), - .pllk3 = WMC_PLLK_8_0w(11869595ul >> 0), + .plln = 8 | WMC_PLL_PRESCALE, + .pllk1 = 0x2d, /* 11869595 */ + .pllk2 = 0x08e, + .pllk3 = 0x19b, .mclkdiv = WMC_MCLKDIV_6, /* 3.0720 MHz */ .filter = WMC_SR_12KHZ, }, [HW_FREQ_16] = /* PLL = 65.536MHz */ { - .plln = WMC_PLLNw(7) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(12414886ul >> 18), - .pllk2 = WMC_PLLK_17_9w(12414886ul >> 9), - .pllk3 = WMC_PLLK_8_0w(12414886ul >> 0), + .plln = 7 | WMC_PLL_PRESCALE, + .pllk1 = 0x2f, /* 12414886 */ + .pllk2 = 0x0b7, + .pllk3 = 0x1a6, .mclkdiv = WMC_MCLKDIV_4, /* 4.0960 MHz */ .filter = WMC_SR_16KHZ, }, @@ -437,19 +437,19 @@ void audiohw_set_frequency(int fsel) }, [HW_FREQ_24] = /* PLL = 73.728 MHz */ { - .plln = WMC_PLLNw(8) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(11869595ul >> 18), - .pllk2 = WMC_PLLK_17_9w(11869595ul >> 9), - .pllk3 = WMC_PLLK_8_0w(11869595ul >> 0), + .plln = 8 | WMC_PLL_PRESCALE, + .pllk1 = 0x2d, /* 11869595 */ + .pllk2 = 0x08e, + .pllk3 = 0x19b, .mclkdiv = WMC_MCLKDIV_3, /* 6.1440 MHz */ .filter = WMC_SR_24KHZ, }, [HW_FREQ_32] = /* PLL = 65.536MHz */ { - .plln = WMC_PLLNw(7) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(12414886ul >> 18), - .pllk2 = WMC_PLLK_17_9w(12414886ul >> 9), - .pllk3 = WMC_PLLK_8_0w(12414886ul >> 0), + .plln = 7 | WMC_PLL_PRESCALE, + .pllk1 = 0x2f, /* 12414886 */ + .pllk2 = 0x0b7, + .pllk3 = 0x1a6, .mclkdiv = WMC_MCLKDIV_2, /* 8.1920 MHz */ .filter = WMC_SR_32KHZ, }, @@ -460,10 +460,10 @@ void audiohw_set_frequency(int fsel) }, [HW_FREQ_48] = /* PLL = 73.728 MHz */ { - .plln = WMC_PLLNw(8) | WMC_PLL_PRESCALE, - .pllk1 = WMC_PLLK_23_18w(11869595ul >> 18), - .pllk2 = WMC_PLLK_17_9w(11869595ul >> 9), - .pllk3 = WMC_PLLK_8_0w(11869595ul >> 0), + .plln = 8 | WMC_PLL_PRESCALE, + .pllk1 = 0x2d, /* 11869595 */ + .pllk2 = 0x08e, + .pllk3 = 0x19b, .mclkdiv = WMC_MCLKDIV_1_5, /* 12.2880 MHz */ .filter = WMC_SR_48KHZ, }, diff --git a/firmware/export/wm8978.h b/firmware/export/wm8978.h index 5b77d1ae30..270c666a4a 100644 --- a/firmware/export/wm8978.h +++ b/firmware/export/wm8978.h @@ -103,13 +103,9 @@ void wmc_clear(unsigned int reg, unsigned int bits); /* Volume masks and macros for digital volumes */ #define WMC_DVOL 0xff -#define WMC_DVOLr(x) ((x) & WMC_DVOL) -#define WMC_DVOLw(x) ((x) & WMC_DVOL) /* Volums masks and macros for analogue volumes */ #define WMC_AVOL 0x3f -#define WMC_AVOLr(x) ((x) & WMC_AVOL) -#define WMC_AVOLw(x) ((x) & WMC_AVOL) /* WMC_SOFTWARE_RESET (0x00) */ #define WMC_RESET @@ -274,14 +270,18 @@ void wmc_clear(unsigned int reg, unsigned int bits); /* 0.5dB steps: Mute:0x00, -127dB:0x01...0dB:0xff */ /*Use WMC_DVOL* macros */ -/* Macros for EQ gain and cutoff */ -#define WMC_EQGC 0x1f -#define WMC_EQGCr(x) ((x) & WMC_EQGC) -#define WMC_EQGCw(x) ((x) & WMC_EQGC) +/* Gain */ +#define WMC_EQG (0x1f << 0) + +/* Cutoff/Center */ +#define WMC_EQC (0x3 << 5) +#define WMC_EQC_POS (5) + +/* Bandwidth */ +#define WMC_EQBW (1 << 8) /* WMC_EQ1_LOW_SHELF (0x12) */ #define WMC_EQ3DMODE (1 << 8) -#define WMC_EQ1C (3 << 5) /* Cutoff */ #define WMC_EQ1C_80HZ (0 << 5) /* 80Hz */ #define WMC_EQ1C_105HZ (1 << 5) /* 105Hz */ #define WMC_EQ1C_135HZ (2 << 5) /* 135Hz */ @@ -289,8 +289,6 @@ void wmc_clear(unsigned int reg, unsigned int bits); /* 00000=+12dB, 00001=+11dB...(-1dB steps)...11000=-12dB, 11001-11111=reserved */ /* WMC_EQ2_PEAK1 (0x13) */ -#define WMC_EQ2BW (1 << 8) -#define WMC_EQ2C (3 << 5) /* Center */ #define WMC_EQ2C_230HZ (0 << 5) /* 230Hz */ #define WMC_EQ2C_300HZ (1 << 5) /* 300Hz */ #define WMC_EQ2C_385HZ (2 << 5) /* 385Hz */ @@ -299,8 +297,6 @@ void wmc_clear(unsigned int reg, unsigned int bits); 11001-11111=reserved */ /* WMC_EQ3_PEAK2 (0x14) */ -#define WMC_EQ3BW (1 << 8) -#define WMC_EQ3C (3 << 5) /* Center */ #define WMC_EQ3C_650HZ (0 << 5) /* 650Hz */ #define WMC_EQ3C_850HZ (1 << 5) /* 850Hz */ #define WMC_EQ3C_1_1KHZ (2 << 5) /* 1.1kHz */ @@ -309,8 +305,6 @@ void wmc_clear(unsigned int reg, unsigned int bits); 11001-11111=reserved */ /* WMC_EQ4_PEAK3 (0x15) */ -#define WMC_EQ4BW (1 << 8) -#define WMC_EQ4C (3 << 5) /* Center */ #define WMC_EQ4C_1_8KHZ (0 << 5) /* 1.8kHz */ #define WMC_EQ4C_2_4KHZ (1 << 5) /* 2.4kHz */ #define WMC_EQ4C_3_2KHZ (2 << 5) /* 3.2kHz */ @@ -319,7 +313,6 @@ void wmc_clear(unsigned int reg, unsigned int bits); 11001-11111=reserved */ /* WMC_EQ5_HIGH_SHELF (0x16) */ -#define WMC_EQ5C (3 << 5) /* Cutoff */ #define WMC_EQ5C_5_3KHZ (0 << 5) /* 5.3kHz */ #define WMC_EQ5C_6_9KHZ (1 << 5) /* 6.9kHz */ #define WMC_EQ5C_9KHZ (2 << 5) /* 9.0kHz */ @@ -331,29 +324,20 @@ void wmc_clear(unsigned int reg, unsigned int bits); #define WMC_LIMEN (1 << 8) /* 0000=750uS, 0001=1.5mS...(x2 each step)...1010-1111=768mS */ #define WMC_LIMDCY (0xf << 4) - #define WMC_LIMDCYr(x) (((x) & WMC_LIMDCY) >> 4) - #define WMC_LIMDCYw(x) (((x) << 4) & WMC_LIMDCY) +#define WMC_LIMDCY_POS (4) /* 0000=94uS, 0001=188uS...(x2 each step)...1011-1111=192mS */ #define WMC_LIMATK (0xf << 0) - #define WMC_LIMATKr(x) ((x) & WMC_LIMATK) - #define WMC_LIMATKw(x) ((x) & WMC_LIMATK) /* WMC_DAC_LIMITER2 (0x19) */ -#define WMC_LIMLVL (7 << 4) /* 000=-1dB, 001=-2dB...(-1dB steps)...101-111:-6dB */ - #define WMC_LIMLVLr(x) (((x) & WMC_LIMLVL) >> 4) - #define WMC_LIMLVLw(x) (((x) << 4) & WMC_LIMLVL) -#define WMC_LIMBOOST (0xf << 0) +#define WMC_LIMLVL (7 << 4) +#define WMC_LIMLVL_POS (4) /* 0000=0dB, 0001=+1dB...1100=+12dB, 1101-1111=reserved */ - #define WMC_LIMBOOSTr(x) (((x) & WMC_LIMBOOST) - #define WMC_LIMBOOSTw(x) (((x) & WMC_LIMBOOST) - +#define WMC_LIMBOOST (0xf << 0) /* Generic notch filter bits and macros */ #define WMC_NFU (1 << 8) #define WMC_NFA (0x7f << 0) -#define WMC_NFAr(x) ((x) & WMC_NFA) -#define WMC_NFAw(x) ((x) & WMC_NFA) /* WMC_NOTCH_FILTER1 (0x1b) */ #define WMC_NFEN (1 << 7) @@ -369,24 +353,18 @@ void wmc_clear(unsigned int reg, unsigned int bits); #define WMC_ALCSEL_BOTH_ON (3 << 7) /* 000=-6.75dB, 001=-0.75dB...(6dB steps)...111=+35.25dB */ #define WMC_ALCMAXGAIN (7 << 3) - #define WMC_ALCMAXGAINr(x) (((x) & WMC_ALCMAXGAIN) >> 3) - #define WMC_ALCMAXGAINw(x) (((x) << 3) & WMC_ALCMAXGAIN) +#define WMC_ALCMAXGAIN_POS (3) /* 000:-12dB...(6dB steps)...111:+30dB */ #define WMC_ALCMINGAIN (7 << 0) - #define WMC_ALCMINGAINr(x) ((x) & WMC_ALCMINGAIN) - #define WMC_ALCMINGAINw(x) ((x) & WMC_ALCMINGAIN) /* WMC_ALC_CONTROL2 (0x21) */ /* 0000=0ms, 0001=2.67ms, 0010=5.33ms... (2x with every step)...43.691s */ #define WMC_ALCHLD (0xf << 4) - #define WMC_ALCHLDr(x) (((x) & WMC_ALCHLD) >> 4) - #define WMC_ALCHLDw(x) (((x) << 4) & WMC_ALCHLD) +#define WMC_ALCHLD_POS (4) /* 1111:-1.5dBFS, 1110:-1.5dBFS, 1101:-3dBFS, 1100:-4.5dBFS... (-1.5dB steps)...0001:-21dBFS, 0000:-22.5dBFS */ #define WMC_ALCLVL (0xf << 0) - #define WMC_ALCLVLr(x) ((x) & WMC_ALCLVL) - #define WMC_ALCLVLw(x) ((x) & WMC_ALCLVL) /* WMC_ALC_CONTROL3 (0x22) */ #define WMC_ALCMODE (1 << 8) @@ -397,43 +375,30 @@ void wmc_clear(unsigned int reg, unsigned int bits); #define WMC_NGEN (1 << 3) /* 000=-39dB, 001=-45dB, 010=-51dB...(6dB steps)...111=-81dB */ #define WMC_NGTH (7 << 0) - #define WMC_NGTHr(x) ((x) & WMC_NGTH) - #define WMC_NGTHw(x) ((x) & WMC_NGTH) /* WMC_PLL_N (0x24) */ #define WMC_PLL_PRESCALE (1 << 4) #define WMC_PLLN (0xf << 0) - #define WMC_PLLNr(x) ((x) & WMC_PLLN) - #define WMC_PLLNw(x) ((x) & WMC_PLLN) /* WMC_PLL_K1 (0x25) */ #define WMC_PLLK_23_18 (0x3f << 0) - #define WMC_PLLK_23_18r(x) ((x) & WMC_PLLK_23_18) - #define WMC_PLLK_23_18w(x) ((x) & WMC_PLLK_23_18) /* WMC_PLL_K2 (0x26) */ #define WMC_PLLK_17_9 (0x1ff << 0) - #define WMC_PLLK_17_9r(x) ((x) & WMC_PLLK_17_9) - #define WMC_PLLK_17_9w(x) ((x) & WMC_PLLK_17_9) /* WMC_PLL_K3 (0x27) */ #define WMC_PLLK_8_0 (0x1ff << 0) - #define WMC_PLLK_8_0r(x) ((x) & WMC_PLLK_8_0) - #define WMC_PLLK_8_0w(x) ((x) & WMC_PLLK_8_0) /* WMC_3D_CONTROL (0x29) */ /* 0000: 0%, 0001: 6.67%...1110: 93.3%, 1111: 100% */ #define WMC_DEPTH3D (0xf << 0) - #define WMC_DEPTH3Dw(x) ((x) & WMC_DEPTH3D) - #define WMC_DEPTH3Dr(x) ((x) & WMC_DEPTH3D) /* WMC_BEEP_CONTROL (0x2b) */ #define WMC_MUTERPGA2INV (1 << 5) #define WMC_INVROUT2 (1 << 4) /* 000=-15dB, 001=-12dB...111=+6dB */ #define WMC_BEEPVOL (7 << 1) - #define WMC_BEEPVOLr(x) (((x) & WMC_BEEPVOL) >> 1) - #define WMC_BEEPVOLw(x) (((x) << 1) & WMC_BEEPVOL) +#define WMC_BEEPVOL_POS (1) #define WMC_BEEPEN (1 << 0) /* WMC_INPUT_CTRL (0x2c) */ @@ -457,23 +422,17 @@ void wmc_clear(unsigned int reg, unsigned int bits); #define WMC_PGABOOSTL (1 << 8) /* 000=disabled, 001=-12dB, 010=-9dB...111=+6dB */ #define WMC_L2_2BOOSTVOL (7 << 4) - #define WMC_L2_2BOOSTVOLr(x) (((x) & WMC_L2_2BOOSTVOL) >> 4) - #define WMC_L2_2BOOSTVOLw(x) (((x) << 4) & WMC_L2_2BOOSTVOL) +#define WMC_L2_2BOOSTVOL_POS (4) /* 000=disabled, 001=-12dB, 010=-9dB...111=+6dB */ #define WMC_AUXL2BOOSTVOL (7 << 0) - #define WMC_AUXL2BOOSTVOLr(x) ((x) & WMC_AUXL2BOOSTVOL) - #define WMC_AUXL2BOOSTVOLw(x) ((x) & WMC_AUXL2BOOSTVOL) /* WMC_RIGHT_ADC_BOOST_CTRL (0x30) */ #define WMC_PGABOOSTR (1 << 8) /* 000=disabled, 001=-12dB, 010=-9dB...111=+6dB */ -#define WMC_R2_2BOOSTVOL (7 << 4) - #define WMC_R2_2BOOSTVOLr(x) (((x) & WMC_R2_2BOOSTVOL) >> 4) - #define WMC_R2_2BOOSTVOLw(x) (((x) << 4) & WMC_R2_2BOOSTVOL) +#define WMC_R2_2BOOSTVOL (7 << 4) +#define WMC_R2_2BOOSTVOL_POS (4) /* 000=disabled, 001=-12dB, 010=-9dB...111=+6dB */ #define WMC_AUXR2BOOSTVOL (7 << 0) - #define WMC_AUXR2BOOSTVOLr(x) ((x) & WMC_AUXR2BOOSTVOL) - #define WMC_AUXR2BOOSTVOLw(x) ((x) & WMC_AUXR2BOOSTVOL) /* WMC_OUTPUT_CTRL (0x31) */ #define WMC_DACL2RMIX (1 << 6) @@ -487,26 +446,22 @@ void wmc_clear(unsigned int reg, unsigned int bits); /* WMC_LEFT_MIXER_CTRL (0x32) */ /* 000=-15dB, 001=-12dB...101=0dB, 110=+3dB, 111=+6dB */ #define WMC_AUXLMIXVOL (7 << 6) - #define WMC_AUXLMIXVOLr(x) (((x) & WMC_AUXLMIXVOL) >> 6) - #define WMC_AUXLMIXVOLw(x) (((x) << 6) & WMC_AUXLMIXVOL) +#define WMC_AUXLMIXVOL_POS (6) #define WMC_AUXL2LMIX (1 << 5) /* 000=-15dB, 001=-12dB...101=0dB, 110=+3dB, 111=+6dB */ #define WMC_BYPLMIXVOL (7 << 2) - #define WMC_BYPLMIXVOLr(x) (((x) & WMC_BYPLMIXVOL) >> 2) - #define WMC_BYPLMIXVOLw(x) (((x) << 2) & WMC_BYPLMIXVOL) +#define WMC_BYPLMIXVOL_POS (2) #define WMC_BYPL2LMIX (1 << 1) #define WMC_DACL2LMIX (1 << 0) /* WMC_RIGHT_MIXER_CTRL (0x33) */ /* 000=-15dB, 001=-12dB...101=0dB, 110=+3dB, 111=+6dB */ #define WMC_AUXRMIXVOL (7 << 6) - #define WMC_AUXRMIXVOLr(x) (((x) & WMC_AUXRMIXVOL) >> 6) - #define WMC_AUXRMIXVOLw(x) (((x) << 6) & WMC_AUXRMIXVOL) +#define WMC_AUXRMIXVOL_POS (6) #define WMC_AUXR2RMIX (1 << 5) /* 000=-15dB, 001=-12dB...101=0dB, 110=+3dB, 111=+6dB */ #define WMC_BYPRMIXVOL (7 << 2) - #define WMC_BYPRMIXVOLr(x) (((x) & WMC_BYPRMIXVOL) >> 2) - #define WMC_BYPRMIXVOLw(x) (((x) << 2) & WMC_BYPRMIXVOL) +#define WMC_BYPRMIXVOL_POS (2) #define WMC_BYPR2RMIX (1 << 1) #define WMC_DACR2RMIX (1 << 0) |