4 * (C) Copyright 2017-2018
5 * Seeed Technology Co., Ltd. <www.seeedstudio.com>
7 * PeterYang <linsheng.yang@seeed.cc>
9 * (C) Copyright 2010-2017
10 * Reuuimlla Technology Co., Ltd. <www.reuuimllatech.com>
11 * huangxin <huangxin@reuuimllatech.com>
13 * some simple description for this code
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.
24 #include <linux/version.h>
26 #define AC101_I2C_ID 4
27 #define _MASTER_AC108 0
28 #define _MASTER_AC101 1
29 #define _MASTER_MULTI_CODEC _MASTER_AC101
31 /* enable headset detecting & headset button pressing */
32 #define CONFIG_AC101_SWITCH_DETECT
35 #define CONFIG_AC10X_TRIG_LOCK 0
39 #define AC101_DBG(format,args...) printk("[AC101] %s() L%d " format, __func__, __LINE__, ##args)
41 #define AC101_DBG(...)
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
45 #define __NO_SND_SOC_CODEC_DRV 1
47 #define __NO_SND_SOC_CODEC_DRV 0
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
66 #ifdef CONFIG_AC101_SWITCH_DETECT
67 enum headphone_mode_u {
69 FOUR_HEADPHONE_PLUGIN,
70 THREE_HEADPHONE_PLUGIN,
75 struct i2c_client *i2c[4];
76 struct regmap* i2cmap[4];
79 #define _FREQ_24_576K 24576000
80 #define _FREQ_22_579K 22579200
81 unsigned mclk; /* master clock or aif_clock/aclk */
83 unsigned char i2s_mode;
84 unsigned char data_protocol;
85 struct delayed_work dlywork;
89 /* member for ac101 .begin */
90 struct snd_soc_codec *codec;
91 struct i2c_client *i2c101;
92 struct regmap* regmap101;
94 struct mutex dac_mutex;
99 struct work_struct codec_resume;
100 struct gpio_desc* gpiod_spk_amp_gate;
102 #ifdef CONFIG_AC101_SWITCH_DETECT
103 struct gpio_desc* gpiod_irq;
105 volatile int irq_cntr;
106 volatile int pullout_cntr;
109 enum headphone_mode_u mode;
110 struct work_struct work_switch;
111 struct work_struct work_clear_irq;
113 struct input_dev* inpdev;
115 /* member for ac101 .end */
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);
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);
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);
142 /* seeed voice card export */
143 int seeed_voice_card_register_set_clock(int stream, int (*set_clock)(int));
145 int ac10x_fill_regcache(struct device* dev, struct regmap* map);