ASoC: ac108: Adds ac108 codec and machine code
[platform/kernel/linux-rpi.git] / sound / soc / codecs / ac10x.h
1 /*
2  * ac10x.h
3  *
4  * (C) Copyright 2017-2018
5  * Seeed Technology Co., Ltd. <www.seeedstudio.com>
6  *
7  * PeterYang <linsheng.yang@seeed.cc>
8  *
9  * (C) Copyright 2010-2017
10  * Reuuimlla Technology Co., Ltd. <www.reuuimllatech.com>
11  * huangxin <huangxin@reuuimllatech.com>
12  *
13  * some simple description for this code
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License as
17  * published by the Free Software Foundation; either version 2 of
18  * the License, or (at your option) any later version.
19  *
20  */
21 #ifndef __AC10X_H__
22 #define __AC10X_H__
23
24 #include <linux/version.h>
25
26 #define AC101_I2C_ID            4
27 #define _MASTER_AC108           0
28 #define _MASTER_AC101           1
29 #define _MASTER_MULTI_CODEC     _MASTER_AC101
30
31 /* enable headset detecting & headset button pressing */
32 #define CONFIG_AC101_SWITCH_DETECT
33
34 /* obsolete */
35 #define CONFIG_AC10X_TRIG_LOCK  0
36
37
38 #ifdef AC101_DEBG
39     #define AC101_DBG(format,args...)  printk("[AC101] %s() L%d " format, __func__, __LINE__, ##args)
40 #else
41     #define AC101_DBG(...)
42 #endif
43
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
45 #define __NO_SND_SOC_CODEC_DRV     1
46 #else
47 #define __NO_SND_SOC_CODEC_DRV     0
48 #endif
49
50 #if __NO_SND_SOC_CODEC_DRV
51 #define codec                      component
52 #define snd_soc_codec              snd_soc_component
53 #define snd_soc_codec_driver       snd_soc_component_driver
54 #define snd_soc_codec_get_drvdata  snd_soc_component_get_drvdata
55 #define snd_soc_codec_get_dapm     snd_soc_component_get_dapm
56 #define snd_soc_codec_get_bias_level snd_soc_component_get_bias_level
57 #define snd_soc_kcontrol_codec     snd_soc_kcontrol_component
58 #define snd_soc_read               snd_soc_component_read32
59 #define snd_soc_register_codec     snd_soc_register_component
60 #define snd_soc_unregister_codec   snd_soc_unregister_component
61 #define snd_soc_update_bits        snd_soc_component_update_bits
62 #define snd_soc_write              snd_soc_component_write
63 #define snd_soc_add_codec_controls snd_soc_add_component_controls
64 #endif
65
66 #ifdef CONFIG_AC101_SWITCH_DETECT
67 enum headphone_mode_u {
68         HEADPHONE_IDLE,
69         FOUR_HEADPHONE_PLUGIN,
70         THREE_HEADPHONE_PLUGIN,
71 };
72 #endif
73
74 struct ac10x_priv {
75         struct i2c_client *i2c[4];
76         struct regmap* i2cmap[4];
77         int codec_cnt;
78         unsigned sysclk;
79 #define _FREQ_24_576K           24576000
80 #define _FREQ_22_579K           22579200
81         unsigned mclk;  /* master clock or aif_clock/aclk */
82         int clk_id;
83         unsigned char i2s_mode;
84         unsigned char data_protocol;
85         struct delayed_work dlywork;
86         int tdm_chips_cnt;
87         int sysclk_en;
88
89         /* member for ac101 .begin */
90         struct snd_soc_codec *codec;
91         struct i2c_client *i2c101;
92         struct regmap* regmap101;
93
94         struct mutex dac_mutex;
95         u8 dac_enable;
96         spinlock_t lock;
97         u8 aif1_clken;
98
99         struct work_struct codec_resume;
100         struct gpio_desc* gpiod_spk_amp_gate;
101
102         #ifdef CONFIG_AC101_SWITCH_DETECT
103         struct gpio_desc* gpiod_irq;
104         long irq;
105         volatile int irq_cntr;
106         volatile int pullout_cntr;
107         volatile int state;
108
109         enum headphone_mode_u mode;
110         struct work_struct work_switch;
111         struct work_struct work_clear_irq;
112
113         struct input_dev* inpdev;
114         #endif
115         /* member for ac101 .end */
116 };
117
118
119 /* AC101 DAI operations */
120 int ac101_audio_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai);
121 void ac101_aif_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai);
122 int ac101_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt);
123 int ac101_hw_params(struct snd_pcm_substream *substream,
124         struct snd_pcm_hw_params *params,
125         struct snd_soc_dai *codec_dai);
126 int ac101_trigger(struct snd_pcm_substream *substream, int cmd,
127                   struct snd_soc_dai *dai);
128 int ac101_aif_mute(struct snd_soc_dai *codec_dai, int mute);
129
130 /* codec driver specific */
131 int ac101_codec_probe(struct snd_soc_codec *codec);
132 int ac101_codec_remove(struct snd_soc_codec *codec);
133 int ac101_codec_suspend(struct snd_soc_codec *codec);
134 int ac101_codec_resume(struct snd_soc_codec *codec);
135 int ac101_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level);
136
137 /* i2c device specific */
138 int ac101_probe(struct i2c_client *i2c, const struct i2c_device_id *id);
139 void ac101_shutdown(struct i2c_client *i2c);
140 int ac101_remove(struct i2c_client *i2c);
141
142 /* seeed voice card export */
143 int seeed_voice_card_register_set_clock(int stream, int (*set_clock)(int));
144
145 int ac10x_fill_regcache(struct device* dev, struct regmap* map);
146
147 #endif//__AC10X_H__