1*1a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 245d44e5aSOndrej Zary #ifndef __SOUND_WM8766_H 345d44e5aSOndrej Zary #define __SOUND_WM8766_H 445d44e5aSOndrej Zary 545d44e5aSOndrej Zary /* 645d44e5aSOndrej Zary * ALSA driver for ICEnsemble VT17xx 745d44e5aSOndrej Zary * 845d44e5aSOndrej Zary * Lowlevel functions for WM8766 codec 945d44e5aSOndrej Zary * 1045d44e5aSOndrej Zary * Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org> 1145d44e5aSOndrej Zary */ 1245d44e5aSOndrej Zary 1345d44e5aSOndrej Zary #define WM8766_REG_DACL1 0x00 1445d44e5aSOndrej Zary #define WM8766_REG_DACR1 0x01 1545d44e5aSOndrej Zary #define WM8766_VOL_MASK 0x1ff /* incl. update bit */ 1645d44e5aSOndrej Zary #define WM8766_VOL_UPDATE (1 << 8) /* update volume */ 1745d44e5aSOndrej Zary #define WM8766_REG_DACCTRL1 0x02 1845d44e5aSOndrej Zary #define WM8766_DAC_MUTEALL (1 << 0) 1945d44e5aSOndrej Zary #define WM8766_DAC_DEEMPALL (1 << 1) 2045d44e5aSOndrej Zary #define WM8766_DAC_PDWN (1 << 2) 2145d44e5aSOndrej Zary #define WM8766_DAC_ATC (1 << 3) 2245d44e5aSOndrej Zary #define WM8766_DAC_IZD (1 << 4) 2345d44e5aSOndrej Zary #define WM8766_DAC_PL_MASK 0x1e0 2445d44e5aSOndrej Zary #define WM8766_DAC_PL_LL (1 << 5) /* L chan: L signal */ 2545d44e5aSOndrej Zary #define WM8766_DAC_PL_LR (2 << 5) /* L chan: R signal */ 2645d44e5aSOndrej Zary #define WM8766_DAC_PL_LB (3 << 5) /* L chan: both */ 2745d44e5aSOndrej Zary #define WM8766_DAC_PL_RL (1 << 7) /* R chan: L signal */ 2845d44e5aSOndrej Zary #define WM8766_DAC_PL_RR (2 << 7) /* R chan: R signal */ 2945d44e5aSOndrej Zary #define WM8766_DAC_PL_RB (3 << 7) /* R chan: both */ 3045d44e5aSOndrej Zary #define WM8766_REG_IFCTRL 0x03 3145d44e5aSOndrej Zary #define WM8766_IF_FMT_RIGHTJ (0 << 0) 3245d44e5aSOndrej Zary #define WM8766_IF_FMT_LEFTJ (1 << 0) 3345d44e5aSOndrej Zary #define WM8766_IF_FMT_I2S (2 << 0) 3445d44e5aSOndrej Zary #define WM8766_IF_FMT_DSP (3 << 0) 3545d44e5aSOndrej Zary #define WM8766_IF_DSP_LATE (1 << 2) /* in DSP mode */ 3645d44e5aSOndrej Zary #define WM8766_IF_LRC_INVERTED (1 << 2) /* in other modes */ 3745d44e5aSOndrej Zary #define WM8766_IF_BCLK_INVERTED (1 << 3) 3845d44e5aSOndrej Zary #define WM8766_IF_IWL_16BIT (0 << 4) 3945d44e5aSOndrej Zary #define WM8766_IF_IWL_20BIT (1 << 4) 4045d44e5aSOndrej Zary #define WM8766_IF_IWL_24BIT (2 << 4) 4145d44e5aSOndrej Zary #define WM8766_IF_IWL_32BIT (3 << 4) 4245d44e5aSOndrej Zary #define WM8766_IF_MASK 0x3f 4345d44e5aSOndrej Zary #define WM8766_PHASE_INVERT1 (1 << 6) 4445d44e5aSOndrej Zary #define WM8766_PHASE_INVERT2 (1 << 7) 4545d44e5aSOndrej Zary #define WM8766_PHASE_INVERT3 (1 << 8) 4645d44e5aSOndrej Zary #define WM8766_REG_DACL2 0x04 4745d44e5aSOndrej Zary #define WM8766_REG_DACR2 0x05 4845d44e5aSOndrej Zary #define WM8766_REG_DACL3 0x06 4945d44e5aSOndrej Zary #define WM8766_REG_DACR3 0x07 5045d44e5aSOndrej Zary #define WM8766_REG_MASTDA 0x08 5145d44e5aSOndrej Zary #define WM8766_REG_DACCTRL2 0x09 5245d44e5aSOndrej Zary #define WM8766_DAC2_ZCD (1 << 0) 5345d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_ALL (0 << 1) 5445d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_1 (1 << 1) 5545d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_2 (2 << 1) 5645d44e5aSOndrej Zary #define WM8766_DAC2_ZFLAG_3 (3 << 1) 5745d44e5aSOndrej Zary #define WM8766_DAC2_MUTE1 (1 << 3) 5845d44e5aSOndrej Zary #define WM8766_DAC2_MUTE2 (1 << 4) 5945d44e5aSOndrej Zary #define WM8766_DAC2_MUTE3 (1 << 5) 6045d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP1 (1 << 6) 6145d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP2 (1 << 7) 6245d44e5aSOndrej Zary #define WM8766_DAC2_DEEMP3 (1 << 8) 6345d44e5aSOndrej Zary #define WM8766_REG_DACCTRL3 0x0a 6445d44e5aSOndrej Zary #define WM8766_DAC3_DACPD1 (1 << 1) 6545d44e5aSOndrej Zary #define WM8766_DAC3_DACPD2 (1 << 2) 6645d44e5aSOndrej Zary #define WM8766_DAC3_DACPD3 (1 << 3) 6745d44e5aSOndrej Zary #define WM8766_DAC3_PWRDNALL (1 << 4) 6845d44e5aSOndrej Zary #define WM8766_DAC3_POWER_MASK 0x1e 6945d44e5aSOndrej Zary #define WM8766_DAC3_MASTER (1 << 5) 7045d44e5aSOndrej Zary #define WM8766_DAC3_DAC128FS (0 << 6) 7145d44e5aSOndrej Zary #define WM8766_DAC3_DAC192FS (1 << 6) 7245d44e5aSOndrej Zary #define WM8766_DAC3_DAC256FS (2 << 6) 7345d44e5aSOndrej Zary #define WM8766_DAC3_DAC384FS (3 << 6) 7445d44e5aSOndrej Zary #define WM8766_DAC3_DAC512FS (4 << 6) 7545d44e5aSOndrej Zary #define WM8766_DAC3_DAC768FS (5 << 6) 7645d44e5aSOndrej Zary #define WM8766_DAC3_MSTR_MASK 0x1e0 7745d44e5aSOndrej Zary #define WM8766_REG_MUTE1 0x0c 7845d44e5aSOndrej Zary #define WM8766_MUTE1_MPD (1 << 6) 7945d44e5aSOndrej Zary #define WM8766_REG_MUTE2 0x0f 8045d44e5aSOndrej Zary #define WM8766_MUTE2_MPD (1 << 5) 8145d44e5aSOndrej Zary #define WM8766_REG_RESET 0x1f 8245d44e5aSOndrej Zary 8345d44e5aSOndrej Zary #define WM8766_REG_COUNT 0x10 /* don't cache the RESET register */ 8445d44e5aSOndrej Zary 8545d44e5aSOndrej Zary struct snd_wm8766; 8645d44e5aSOndrej Zary 8745d44e5aSOndrej Zary struct snd_wm8766_ops { 8845d44e5aSOndrej Zary void (*write)(struct snd_wm8766 *wm, u16 addr, u16 data); 8945d44e5aSOndrej Zary }; 9045d44e5aSOndrej Zary 9145d44e5aSOndrej Zary enum snd_wm8766_ctl_id { 9245d44e5aSOndrej Zary WM8766_CTL_CH1_VOL, 9345d44e5aSOndrej Zary WM8766_CTL_CH2_VOL, 9445d44e5aSOndrej Zary WM8766_CTL_CH3_VOL, 9545d44e5aSOndrej Zary WM8766_CTL_CH1_SW, 9645d44e5aSOndrej Zary WM8766_CTL_CH2_SW, 9745d44e5aSOndrej Zary WM8766_CTL_CH3_SW, 9845d44e5aSOndrej Zary WM8766_CTL_PHASE1_SW, 9945d44e5aSOndrej Zary WM8766_CTL_PHASE2_SW, 10045d44e5aSOndrej Zary WM8766_CTL_PHASE3_SW, 10145d44e5aSOndrej Zary WM8766_CTL_DEEMPH1_SW, 10245d44e5aSOndrej Zary WM8766_CTL_DEEMPH2_SW, 10345d44e5aSOndrej Zary WM8766_CTL_DEEMPH3_SW, 10445d44e5aSOndrej Zary WM8766_CTL_IZD_SW, 10545d44e5aSOndrej Zary WM8766_CTL_ZC_SW, 10645d44e5aSOndrej Zary 10745d44e5aSOndrej Zary WM8766_CTL_COUNT, 10845d44e5aSOndrej Zary }; 10945d44e5aSOndrej Zary 11045d44e5aSOndrej Zary #define WM8766_ENUM_MAX 16 11145d44e5aSOndrej Zary 11245d44e5aSOndrej Zary #define WM8766_FLAG_STEREO (1 << 0) 11345d44e5aSOndrej Zary #define WM8766_FLAG_VOL_UPDATE (1 << 1) 11445d44e5aSOndrej Zary #define WM8766_FLAG_INVERT (1 << 2) 11545d44e5aSOndrej Zary #define WM8766_FLAG_LIM (1 << 3) 11645d44e5aSOndrej Zary #define WM8766_FLAG_ALC (1 << 4) 11745d44e5aSOndrej Zary 11845d44e5aSOndrej Zary struct snd_wm8766_ctl { 11945d44e5aSOndrej Zary struct snd_kcontrol *kctl; 120a2af050fSTakashi Iwai const char *name; 12145d44e5aSOndrej Zary snd_ctl_elem_type_t type; 12245d44e5aSOndrej Zary const char *const enum_names[WM8766_ENUM_MAX]; 12345d44e5aSOndrej Zary const unsigned int *tlv; 12445d44e5aSOndrej Zary u16 reg1, reg2, mask1, mask2, min, max, flags; 12545d44e5aSOndrej Zary void (*set)(struct snd_wm8766 *wm, u16 ch1, u16 ch2); 12645d44e5aSOndrej Zary void (*get)(struct snd_wm8766 *wm, u16 *ch1, u16 *ch2); 12745d44e5aSOndrej Zary }; 12845d44e5aSOndrej Zary 12945d44e5aSOndrej Zary enum snd_wm8766_agc_mode { WM8766_AGC_OFF, WM8766_AGC_LIM, WM8766_AGC_ALC }; 13045d44e5aSOndrej Zary 13145d44e5aSOndrej Zary struct snd_wm8766 { 13245d44e5aSOndrej Zary struct snd_card *card; 13345d44e5aSOndrej Zary struct snd_wm8766_ctl ctl[WM8766_CTL_COUNT]; 13445d44e5aSOndrej Zary enum snd_wm8766_agc_mode agc_mode; 13545d44e5aSOndrej Zary struct snd_wm8766_ops ops; 13645d44e5aSOndrej Zary u16 regs[WM8766_REG_COUNT]; /* 9-bit registers */ 13745d44e5aSOndrej Zary }; 13845d44e5aSOndrej Zary 13945d44e5aSOndrej Zary 14045d44e5aSOndrej Zary 14145d44e5aSOndrej Zary void snd_wm8766_init(struct snd_wm8766 *wm); 14245d44e5aSOndrej Zary void snd_wm8766_resume(struct snd_wm8766 *wm); 14345d44e5aSOndrej Zary void snd_wm8766_set_if(struct snd_wm8766 *wm, u16 dac); 14445d44e5aSOndrej Zary void snd_wm8766_volume_restore(struct snd_wm8766 *wm); 14545d44e5aSOndrej Zary int snd_wm8766_build_controls(struct snd_wm8766 *wm); 14645d44e5aSOndrej Zary 14745d44e5aSOndrej Zary #endif /* __SOUND_WM8766_H */ 148