xref: /linux/sound/soc/codecs/arizona.h (revision bc9ab6d31c4fde1016ecc6606913ed0d52b3ed76)
107ed873eSMark Brown /*
207ed873eSMark Brown  * arizona.h - Wolfson Arizona class device shared support
307ed873eSMark Brown  *
407ed873eSMark Brown  * Copyright 2012 Wolfson Microelectronics plc
507ed873eSMark Brown  *
607ed873eSMark Brown  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
707ed873eSMark Brown  *
807ed873eSMark Brown  * This program is free software; you can redistribute it and/or modify
907ed873eSMark Brown  * it under the terms of the GNU General Public License version 2 as
1007ed873eSMark Brown  * published by the Free Software Foundation.
1107ed873eSMark Brown  */
1207ed873eSMark Brown 
1307ed873eSMark Brown #ifndef _ASOC_ARIZONA_H
1407ed873eSMark Brown #define _ASOC_ARIZONA_H
1507ed873eSMark Brown 
1607ed873eSMark Brown #include <linux/completion.h>
1707ed873eSMark Brown 
1807ed873eSMark Brown #include <sound/soc.h>
1907ed873eSMark Brown 
200b09df66SMark Brown #include "wm_adsp.h"
210b09df66SMark Brown 
2207ed873eSMark Brown #define ARIZONA_CLK_SYSCLK         1
2307ed873eSMark Brown #define ARIZONA_CLK_ASYNCCLK       2
24cbd840daSMark Brown #define ARIZONA_CLK_OPCLK          3
25cbd840daSMark Brown #define ARIZONA_CLK_ASYNC_OPCLK    4
2607ed873eSMark Brown 
2707ed873eSMark Brown #define ARIZONA_CLK_SRC_MCLK1    0x0
2807ed873eSMark Brown #define ARIZONA_CLK_SRC_MCLK2    0x1
2907ed873eSMark Brown #define ARIZONA_CLK_SRC_FLL1     0x4
3007ed873eSMark Brown #define ARIZONA_CLK_SRC_FLL2     0x5
3107ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF1BCLK 0x8
3207ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF2BCLK 0x9
3307ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF3BCLK 0xa
3407ed873eSMark Brown 
3507ed873eSMark Brown #define ARIZONA_FLL_SRC_MCLK1      0
3607ed873eSMark Brown #define ARIZONA_FLL_SRC_MCLK2      1
3707ed873eSMark Brown #define ARIZONA_FLL_SRC_SLIMCLK    2
3807ed873eSMark Brown #define ARIZONA_FLL_SRC_FLL1       3
3907ed873eSMark Brown #define ARIZONA_FLL_SRC_FLL2       4
4007ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF1BCLK   5
4107ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF2BCLK   6
4207ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF3BCLK   7
4307ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF1LRCLK  8
4407ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF2LRCLK  9
4507ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF3LRCLK 10
4607ed873eSMark Brown 
4707ed873eSMark Brown #define ARIZONA_MIXER_VOL_MASK             0x00FE
4807ed873eSMark Brown #define ARIZONA_MIXER_VOL_SHIFT                 1
4907ed873eSMark Brown #define ARIZONA_MIXER_VOL_WIDTH                 7
5007ed873eSMark Brown 
510b09df66SMark Brown #define ARIZONA_MAX_DAI  4
520b09df66SMark Brown #define ARIZONA_MAX_ADSP 4
535b2eec3fSMark Brown 
5407ed873eSMark Brown struct arizona;
550b09df66SMark Brown struct wm_adsp;
5607ed873eSMark Brown 
575b2eec3fSMark Brown struct arizona_dai_priv {
585b2eec3fSMark Brown 	int clk;
595b2eec3fSMark Brown };
605b2eec3fSMark Brown 
6107ed873eSMark Brown struct arizona_priv {
620b09df66SMark Brown 	struct wm_adsp adsp[ARIZONA_MAX_ADSP];
6307ed873eSMark Brown 	struct arizona *arizona;
6407ed873eSMark Brown 	int sysclk;
6507ed873eSMark Brown 	int asyncclk;
665b2eec3fSMark Brown 	struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
6707ed873eSMark Brown };
6807ed873eSMark Brown 
6991660bd6SMark Brown #define ARIZONA_NUM_MIXER_INPUTS 99
7007ed873eSMark Brown 
7107ed873eSMark Brown extern const unsigned int arizona_mixer_tlv[];
7207ed873eSMark Brown extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
7307ed873eSMark Brown extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
7407ed873eSMark Brown 
7507ed873eSMark Brown #define ARIZONA_MIXER_CONTROLS(name, base) \
7607ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1,		\
7707ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
7807ed873eSMark Brown 			     arizona_mixer_tlv),			\
7907ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3,		\
8007ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
8107ed873eSMark Brown 			     arizona_mixer_tlv),			\
8207ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5,		\
8307ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
8407ed873eSMark Brown 			     arizona_mixer_tlv),			\
8507ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7,		\
8607ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
8707ed873eSMark Brown 			     arizona_mixer_tlv)
8807ed873eSMark Brown 
8907ed873eSMark Brown #define ARIZONA_MUX_ENUM_DECL(name, reg) \
9007ed873eSMark Brown 	SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff,			\
9107ed873eSMark Brown 				   arizona_mixer_texts, arizona_mixer_values)
9207ed873eSMark Brown 
9307ed873eSMark Brown #define ARIZONA_MUX_CTL_DECL(name) \
9407ed873eSMark Brown 	const struct snd_kcontrol_new name##_mux =	\
9507ed873eSMark Brown 		SOC_DAPM_VALUE_ENUM("Route", name##_enum)
9607ed873eSMark Brown 
9717bd09e5SCharles Keepax #define ARIZONA_MUX_ENUMS(name, base_reg) \
9817bd09e5SCharles Keepax 	static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg);      \
9917bd09e5SCharles Keepax 	static ARIZONA_MUX_CTL_DECL(name)
10017bd09e5SCharles Keepax 
10107ed873eSMark Brown #define ARIZONA_MIXER_ENUMS(name, base_reg) \
10217bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_in1, base_reg);     \
10317bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
10417bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
10517bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
10607ed873eSMark Brown 
1070b09df66SMark Brown #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
10817bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux1, base_reg);	\
10917bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8);	\
11017bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16);	\
11117bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24);	\
11217bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32);	\
11317bd09e5SCharles Keepax 	ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
1140b09df66SMark Brown 
11507ed873eSMark Brown #define ARIZONA_MUX(name, ctrl) \
11607ed873eSMark Brown 	SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
11707ed873eSMark Brown 
11817bd09e5SCharles Keepax #define ARIZONA_MUX_WIDGETS(name, name_str) \
11917bd09e5SCharles Keepax 	ARIZONA_MUX(name_str " Input", &name##_mux)
12017bd09e5SCharles Keepax 
12107ed873eSMark Brown #define ARIZONA_MIXER_WIDGETS(name, name_str)	\
12207ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
12307ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
12407ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
12507ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
12607ed873eSMark Brown 	SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
12707ed873eSMark Brown 
1280b09df66SMark Brown #define ARIZONA_DSP_WIDGETS(name, name_str) \
1290b09df66SMark Brown 	ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
1300b09df66SMark Brown 	ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
1310b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
1320b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
1330b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
1340b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
1350b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
1360b09df66SMark Brown 	ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
1370b09df66SMark Brown 
13817bd09e5SCharles Keepax #define ARIZONA_MUX_ROUTES(name) \
13917bd09e5SCharles Keepax 	ARIZONA_MIXER_INPUT_ROUTES(name " Input")
14017bd09e5SCharles Keepax 
14107ed873eSMark Brown #define ARIZONA_MIXER_ROUTES(widget, name) \
14207ed873eSMark Brown 	{ widget, NULL, name " Mixer" },         \
14307ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 1" }, \
14407ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 2" }, \
14507ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 3" }, \
14607ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 4" }, \
14707ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
14807ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
14907ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
15007ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
15107ed873eSMark Brown 
1520b09df66SMark Brown #define ARIZONA_DSP_ROUTES(name) \
1530b09df66SMark Brown 	{ name, NULL, name " Aux 1" }, \
1540b09df66SMark Brown 	{ name, NULL, name " Aux 2" }, \
1550b09df66SMark Brown 	{ name, NULL, name " Aux 3" }, \
1560b09df66SMark Brown 	{ name, NULL, name " Aux 4" }, \
1570b09df66SMark Brown 	{ name, NULL, name " Aux 5" }, \
1580b09df66SMark Brown 	{ name, NULL, name " Aux 6" }, \
1590b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
1600b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
1610b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
1620b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
1630b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
1640b09df66SMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
1650b09df66SMark Brown 	ARIZONA_MIXER_ROUTES(name, name "L"), \
1660b09df66SMark Brown 	ARIZONA_MIXER_ROUTES(name, name "R")
1670b09df66SMark Brown 
168e853a00fSMark Brown extern const struct soc_enum arizona_in_vi_ramp;
169e853a00fSMark Brown extern const struct soc_enum arizona_in_vd_ramp;
170e853a00fSMark Brown 
171e853a00fSMark Brown extern const struct soc_enum arizona_out_vi_ramp;
172e853a00fSMark Brown extern const struct soc_enum arizona_out_vd_ramp;
173e853a00fSMark Brown 
17407ed873eSMark Brown extern const struct soc_enum arizona_lhpf1_mode;
17507ed873eSMark Brown extern const struct soc_enum arizona_lhpf2_mode;
17607ed873eSMark Brown extern const struct soc_enum arizona_lhpf3_mode;
17707ed873eSMark Brown extern const struct soc_enum arizona_lhpf4_mode;
17807ed873eSMark Brown 
179845571ccSMark Brown extern const struct soc_enum arizona_ng_hold;
180845571ccSMark Brown 
18107ed873eSMark Brown extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
18207ed873eSMark Brown 			 struct snd_kcontrol *kcontrol,
18307ed873eSMark Brown 			 int event);
18407ed873eSMark Brown extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
18507ed873eSMark Brown 			  struct snd_kcontrol *kcontrol,
18607ed873eSMark Brown 			  int event);
18707ed873eSMark Brown 
18807ed873eSMark Brown extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
18907ed873eSMark Brown 			      int source, unsigned int freq, int dir);
19007ed873eSMark Brown 
19107ed873eSMark Brown extern const struct snd_soc_dai_ops arizona_dai_ops;
19207ed873eSMark Brown 
19307ed873eSMark Brown #define ARIZONA_FLL_NAME_LEN 20
19407ed873eSMark Brown 
19507ed873eSMark Brown struct arizona_fll {
19607ed873eSMark Brown 	struct arizona *arizona;
19707ed873eSMark Brown 	int id;
19807ed873eSMark Brown 	unsigned int base;
1992b4d39fcSMark Brown 	unsigned int vco_mult;
20007ed873eSMark Brown 	struct completion lock;
20107ed873eSMark Brown 	struct completion ok;
2021cbe4bcaSMark Brown 	unsigned int fref;
2031cbe4bcaSMark Brown 	unsigned int fout;
20407ed873eSMark Brown 
20507ed873eSMark Brown 	char lock_name[ARIZONA_FLL_NAME_LEN];
20607ed873eSMark Brown 	char clock_ok_name[ARIZONA_FLL_NAME_LEN];
20707ed873eSMark Brown };
20807ed873eSMark Brown 
20907ed873eSMark Brown extern int arizona_init_fll(struct arizona *arizona, int id, int base,
21007ed873eSMark Brown 			    int lock_irq, int ok_irq, struct arizona_fll *fll);
21107ed873eSMark Brown extern int arizona_set_fll(struct arizona_fll *fll, int source,
21207ed873eSMark Brown 			   unsigned int Fref, unsigned int Fout);
21307ed873eSMark Brown 
2145b2eec3fSMark Brown extern int arizona_init_dai(struct arizona_priv *priv, int dai);
2155b2eec3fSMark Brown 
216*bc9ab6d3SMark Brown int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
217*bc9ab6d3SMark Brown 			    bool diff);
218*bc9ab6d3SMark Brown 
21907ed873eSMark Brown #endif
220