xref: /linux/sound/soc/codecs/arizona.h (revision 2b4d39fc2a80e271ac8d44fccd02277a4b63c557)
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 
2007ed873eSMark Brown #define ARIZONA_CLK_SYSCLK   1
2107ed873eSMark Brown #define ARIZONA_CLK_ASYNCCLK 2
2207ed873eSMark Brown 
2307ed873eSMark Brown #define ARIZONA_CLK_SRC_MCLK1    0x0
2407ed873eSMark Brown #define ARIZONA_CLK_SRC_MCLK2    0x1
2507ed873eSMark Brown #define ARIZONA_CLK_SRC_FLL1     0x4
2607ed873eSMark Brown #define ARIZONA_CLK_SRC_FLL2     0x5
2707ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF1BCLK 0x8
2807ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF2BCLK 0x9
2907ed873eSMark Brown #define ARIZONA_CLK_SRC_AIF3BCLK 0xa
3007ed873eSMark Brown 
3107ed873eSMark Brown #define ARIZONA_FLL_SRC_MCLK1      0
3207ed873eSMark Brown #define ARIZONA_FLL_SRC_MCLK2      1
3307ed873eSMark Brown #define ARIZONA_FLL_SRC_SLIMCLK    2
3407ed873eSMark Brown #define ARIZONA_FLL_SRC_FLL1       3
3507ed873eSMark Brown #define ARIZONA_FLL_SRC_FLL2       4
3607ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF1BCLK   5
3707ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF2BCLK   6
3807ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF3BCLK   7
3907ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF1LRCLK  8
4007ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF2LRCLK  9
4107ed873eSMark Brown #define ARIZONA_FLL_SRC_AIF3LRCLK 10
4207ed873eSMark Brown 
4307ed873eSMark Brown #define ARIZONA_MIXER_VOL_MASK             0x00FE
4407ed873eSMark Brown #define ARIZONA_MIXER_VOL_SHIFT                 1
4507ed873eSMark Brown #define ARIZONA_MIXER_VOL_WIDTH                 7
4607ed873eSMark Brown 
475b2eec3fSMark Brown #define ARIZONA_MAX_DAI 3
485b2eec3fSMark Brown 
4907ed873eSMark Brown struct arizona;
5007ed873eSMark Brown 
515b2eec3fSMark Brown struct arizona_dai_priv {
525b2eec3fSMark Brown 	int clk;
535b2eec3fSMark Brown };
545b2eec3fSMark Brown 
5507ed873eSMark Brown struct arizona_priv {
5607ed873eSMark Brown 	struct arizona *arizona;
5707ed873eSMark Brown 	int sysclk;
5807ed873eSMark Brown 	int asyncclk;
595b2eec3fSMark Brown 	struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
6007ed873eSMark Brown };
6107ed873eSMark Brown 
62c9c56fd0SMark Brown #define ARIZONA_NUM_MIXER_INPUTS 57
6307ed873eSMark Brown 
6407ed873eSMark Brown extern const unsigned int arizona_mixer_tlv[];
6507ed873eSMark Brown extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
6607ed873eSMark Brown extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
6707ed873eSMark Brown 
6807ed873eSMark Brown #define ARIZONA_MIXER_CONTROLS(name, base) \
6907ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1,		\
7007ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
7107ed873eSMark Brown 			     arizona_mixer_tlv),			\
7207ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3,		\
7307ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
7407ed873eSMark Brown 			     arizona_mixer_tlv),			\
7507ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5,		\
7607ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
7707ed873eSMark Brown 			     arizona_mixer_tlv),			\
7807ed873eSMark Brown 	SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7,		\
7907ed873eSMark Brown 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
8007ed873eSMark Brown 			     arizona_mixer_tlv)
8107ed873eSMark Brown 
8207ed873eSMark Brown #define ARIZONA_MUX_ENUM_DECL(name, reg) \
8307ed873eSMark Brown 	SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff,			\
8407ed873eSMark Brown 				   arizona_mixer_texts, arizona_mixer_values)
8507ed873eSMark Brown 
8607ed873eSMark Brown #define ARIZONA_MUX_CTL_DECL(name) \
8707ed873eSMark Brown 	const struct snd_kcontrol_new name##_mux =	\
8807ed873eSMark Brown 		SOC_DAPM_VALUE_ENUM("Route", name##_enum)
8907ed873eSMark Brown 
9007ed873eSMark Brown #define ARIZONA_MIXER_ENUMS(name, base_reg) \
9107ed873eSMark Brown 	static ARIZONA_MUX_ENUM_DECL(name##_in1_enum, base_reg);      \
9207ed873eSMark Brown 	static ARIZONA_MUX_ENUM_DECL(name##_in2_enum, base_reg + 2);  \
9307ed873eSMark Brown 	static ARIZONA_MUX_ENUM_DECL(name##_in3_enum, base_reg + 4);  \
9407ed873eSMark Brown 	static ARIZONA_MUX_ENUM_DECL(name##_in4_enum, base_reg + 6);  \
9507ed873eSMark Brown 	static ARIZONA_MUX_CTL_DECL(name##_in1); \
9607ed873eSMark Brown 	static ARIZONA_MUX_CTL_DECL(name##_in2); \
9707ed873eSMark Brown 	static ARIZONA_MUX_CTL_DECL(name##_in3); \
9807ed873eSMark Brown 	static ARIZONA_MUX_CTL_DECL(name##_in4)
9907ed873eSMark Brown 
10007ed873eSMark Brown #define ARIZONA_MUX(name, ctrl) \
10107ed873eSMark Brown 	SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
10207ed873eSMark Brown 
10307ed873eSMark Brown #define ARIZONA_MIXER_WIDGETS(name, name_str)	\
10407ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
10507ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
10607ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
10707ed873eSMark Brown 	ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
10807ed873eSMark Brown 	SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
10907ed873eSMark Brown 
11007ed873eSMark Brown #define ARIZONA_MIXER_ROUTES(widget, name) \
11107ed873eSMark Brown 	{ widget, NULL, name " Mixer" },         \
11207ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 1" }, \
11307ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 2" }, \
11407ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 3" }, \
11507ed873eSMark Brown 	{ name " Mixer", NULL, name " Input 4" }, \
11607ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
11707ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
11807ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
11907ed873eSMark Brown 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
12007ed873eSMark Brown 
12107ed873eSMark Brown extern const struct soc_enum arizona_lhpf1_mode;
12207ed873eSMark Brown extern const struct soc_enum arizona_lhpf2_mode;
12307ed873eSMark Brown extern const struct soc_enum arizona_lhpf3_mode;
12407ed873eSMark Brown extern const struct soc_enum arizona_lhpf4_mode;
12507ed873eSMark Brown 
12607ed873eSMark Brown extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
12707ed873eSMark Brown 			 struct snd_kcontrol *kcontrol,
12807ed873eSMark Brown 			 int event);
12907ed873eSMark Brown extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
13007ed873eSMark Brown 			  struct snd_kcontrol *kcontrol,
13107ed873eSMark Brown 			  int event);
13207ed873eSMark Brown 
13307ed873eSMark Brown extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
13407ed873eSMark Brown 			      int source, unsigned int freq, int dir);
13507ed873eSMark Brown 
13607ed873eSMark Brown extern const struct snd_soc_dai_ops arizona_dai_ops;
13707ed873eSMark Brown 
13807ed873eSMark Brown #define ARIZONA_FLL_NAME_LEN 20
13907ed873eSMark Brown 
14007ed873eSMark Brown struct arizona_fll {
14107ed873eSMark Brown 	struct arizona *arizona;
14207ed873eSMark Brown 	int id;
14307ed873eSMark Brown 	unsigned int base;
144*2b4d39fcSMark Brown 	unsigned int vco_mult;
14507ed873eSMark Brown 	struct completion lock;
14607ed873eSMark Brown 	struct completion ok;
14707ed873eSMark Brown 
14807ed873eSMark Brown 	char lock_name[ARIZONA_FLL_NAME_LEN];
14907ed873eSMark Brown 	char clock_ok_name[ARIZONA_FLL_NAME_LEN];
15007ed873eSMark Brown };
15107ed873eSMark Brown 
15207ed873eSMark Brown extern int arizona_init_fll(struct arizona *arizona, int id, int base,
15307ed873eSMark Brown 			    int lock_irq, int ok_irq, struct arizona_fll *fll);
15407ed873eSMark Brown extern int arizona_set_fll(struct arizona_fll *fll, int source,
15507ed873eSMark Brown 			   unsigned int Fref, unsigned int Fout);
15607ed873eSMark Brown 
1575b2eec3fSMark Brown extern int arizona_init_dai(struct arizona_priv *priv, int dai);
1585b2eec3fSMark Brown 
15907ed873eSMark Brown #endif
160