blob: da597e456beb253027fa88c34b8f350af01aa438 [file] [log] [blame]
Thomas Gleixner4c694f22019-05-23 11:14:56 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Emilio López45fb6b62015-09-12 15:26:24 +02002/*
3 * Copyright 2014 Emilio López <emilio@elopez.com.ar>
4 * Copyright 2014 Jon Smirl <jonsmirl@gmail.com>
5 * Copyright 2015 Maxime Ripard <maxime.ripard@free-electrons.com>
Adam Sampson474d1472015-10-27 21:00:45 +00006 * Copyright 2015 Adam Sampson <ats@offog.org>
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08007 * Copyright 2016 Chen-Yu Tsai <wens@csie.org>
Emilio López45fb6b62015-09-12 15:26:24 +02008 *
9 * Based on the Allwinner SDK driver, released under the GPL.
Emilio López45fb6b62015-09-12 15:26:24 +020010 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/delay.h>
17#include <linux/slab.h>
18#include <linux/of.h>
Emilio López45fb6b62015-09-12 15:26:24 +020019#include <linux/of_address.h>
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +080020#include <linux/of_device.h>
21#include <linux/of_platform.h>
Emilio López45fb6b62015-09-12 15:26:24 +020022#include <linux/clk.h>
23#include <linux/regmap.h>
Chen-Yu Tsai9aead152016-11-07 18:06:58 +080024#include <linux/reset.h>
Hans de Goede40592622015-12-11 19:43:57 +010025#include <linux/gpio/consumer.h>
Emilio López45fb6b62015-09-12 15:26:24 +020026
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/tlv.h>
32#include <sound/initval.h>
33#include <sound/dmaengine_pcm.h>
34
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +080035/* Codec DAC digital controls and FIFO registers */
Emilio López45fb6b62015-09-12 15:26:24 +020036#define SUN4I_CODEC_DAC_DPC (0x00)
37#define SUN4I_CODEC_DAC_DPC_EN_DA (31)
38#define SUN4I_CODEC_DAC_DPC_DVOL (12)
39#define SUN4I_CODEC_DAC_FIFOC (0x04)
40#define SUN4I_CODEC_DAC_FIFOC_DAC_FS (29)
41#define SUN4I_CODEC_DAC_FIFOC_FIR_VERSION (28)
42#define SUN4I_CODEC_DAC_FIFOC_SEND_LASAT (26)
43#define SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE (24)
44#define SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT (21)
45#define SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL (8)
46#define SUN4I_CODEC_DAC_FIFOC_MONO_EN (6)
47#define SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS (5)
48#define SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN (4)
49#define SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH (0)
50#define SUN4I_CODEC_DAC_FIFOS (0x08)
51#define SUN4I_CODEC_DAC_TXDATA (0x0c)
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +080052
53/* Codec DAC side analog signal controls */
Emilio López45fb6b62015-09-12 15:26:24 +020054#define SUN4I_CODEC_DAC_ACTL (0x10)
55#define SUN4I_CODEC_DAC_ACTL_DACAENR (31)
56#define SUN4I_CODEC_DAC_ACTL_DACAENL (30)
57#define SUN4I_CODEC_DAC_ACTL_MIXEN (29)
Danny Milosavljevic67690c22019-01-30 11:39:44 +010058#define SUN4I_CODEC_DAC_ACTL_LNG (26)
Danny Milosavljevic50d16412019-01-30 11:39:43 +010059#define SUN4I_CODEC_DAC_ACTL_FMG (23)
Danny Milosavljevic63bd8482019-01-30 11:39:37 +010060#define SUN4I_CODEC_DAC_ACTL_MICG (20)
Danny Milosavljevic67690c22019-01-30 11:39:44 +010061#define SUN4I_CODEC_DAC_ACTL_LLNS (19)
62#define SUN4I_CODEC_DAC_ACTL_RLNS (18)
Danny Milosavljevic50d16412019-01-30 11:39:43 +010063#define SUN4I_CODEC_DAC_ACTL_LFMS (17)
64#define SUN4I_CODEC_DAC_ACTL_RFMS (16)
Emilio López45fb6b62015-09-12 15:26:24 +020065#define SUN4I_CODEC_DAC_ACTL_LDACLMIXS (15)
66#define SUN4I_CODEC_DAC_ACTL_RDACRMIXS (14)
67#define SUN4I_CODEC_DAC_ACTL_LDACRMIXS (13)
Danny Milosavljevic44a1f4e2019-01-30 11:39:42 +010068#define SUN4I_CODEC_DAC_ACTL_MIC1LS (12)
69#define SUN4I_CODEC_DAC_ACTL_MIC1RS (11)
70#define SUN4I_CODEC_DAC_ACTL_MIC2LS (10)
71#define SUN4I_CODEC_DAC_ACTL_MIC2RS (9)
Emilio López45fb6b62015-09-12 15:26:24 +020072#define SUN4I_CODEC_DAC_ACTL_DACPAS (8)
73#define SUN4I_CODEC_DAC_ACTL_MIXPAS (7)
74#define SUN4I_CODEC_DAC_ACTL_PA_MUTE (6)
75#define SUN4I_CODEC_DAC_ACTL_PA_VOL (0)
76#define SUN4I_CODEC_DAC_TUNE (0x14)
77#define SUN4I_CODEC_DAC_DEBUG (0x18)
78
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +080079/* Codec ADC digital controls and FIFO registers */
Emilio López45fb6b62015-09-12 15:26:24 +020080#define SUN4I_CODEC_ADC_FIFOC (0x1c)
Maxime Ripard1fb34b42015-11-30 16:37:47 +010081#define SUN4I_CODEC_ADC_FIFOC_ADC_FS (29)
Emilio López45fb6b62015-09-12 15:26:24 +020082#define SUN4I_CODEC_ADC_FIFOC_EN_AD (28)
83#define SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE (24)
84#define SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL (8)
85#define SUN4I_CODEC_ADC_FIFOC_MONO_EN (7)
86#define SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS (6)
87#define SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN (4)
88#define SUN4I_CODEC_ADC_FIFOC_FIFO_FLUSH (0)
89#define SUN4I_CODEC_ADC_FIFOS (0x20)
90#define SUN4I_CODEC_ADC_RXDATA (0x24)
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +080091
92/* Codec ADC side analog signal controls */
Emilio López45fb6b62015-09-12 15:26:24 +020093#define SUN4I_CODEC_ADC_ACTL (0x28)
94#define SUN4I_CODEC_ADC_ACTL_ADC_R_EN (31)
95#define SUN4I_CODEC_ADC_ACTL_ADC_L_EN (30)
96#define SUN4I_CODEC_ADC_ACTL_PREG1EN (29)
97#define SUN4I_CODEC_ADC_ACTL_PREG2EN (28)
98#define SUN4I_CODEC_ADC_ACTL_VMICEN (27)
Danny Milosavljevicb329c782019-01-30 11:39:40 +010099#define SUN4I_CODEC_ADC_ACTL_PREG1 (25)
100#define SUN4I_CODEC_ADC_ACTL_PREG2 (23)
Emilio López45fb6b62015-09-12 15:26:24 +0200101#define SUN4I_CODEC_ADC_ACTL_VADCG (20)
102#define SUN4I_CODEC_ADC_ACTL_ADCIS (17)
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100103#define SUN4I_CODEC_ADC_ACTL_LNPREG (13)
Emilio López45fb6b62015-09-12 15:26:24 +0200104#define SUN4I_CODEC_ADC_ACTL_PA_EN (4)
105#define SUN4I_CODEC_ADC_ACTL_DDE (3)
106#define SUN4I_CODEC_ADC_DEBUG (0x2c)
107
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +0800108/* FIFO counters */
Emilio López45fb6b62015-09-12 15:26:24 +0200109#define SUN4I_CODEC_DAC_TXCNT (0x30)
110#define SUN4I_CODEC_ADC_RXCNT (0x34)
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +0800111
112/* Calibration register (sun7i only) */
Danny Milosavljevic4f0c4e92016-09-22 09:13:12 +0200113#define SUN7I_CODEC_AC_DAC_CAL (0x38)
Chen-Yu Tsaibd720ec2016-11-03 15:55:45 +0800114
115/* Microphone controls (sun7i only) */
Danny Milosavljevic4f0c4e92016-09-22 09:13:12 +0200116#define SUN7I_CODEC_AC_MIC_PHONE_CAL (0x3c)
Emilio López45fb6b62015-09-12 15:26:24 +0200117
Danny Milosavljevicb329c782019-01-30 11:39:40 +0100118#define SUN7I_CODEC_AC_MIC_PHONE_CAL_PREG1 (29)
119#define SUN7I_CODEC_AC_MIC_PHONE_CAL_PREG2 (26)
120
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800121/*
122 * sun6i specific registers
123 *
124 * sun6i shares the same digital control and FIFO registers as sun4i,
125 * but only the DAC digital controls are at the same offset. The others
126 * have been moved around to accommodate extra analog controls.
127 */
128
129/* Codec DAC digital controls and FIFO registers */
130#define SUN6I_CODEC_ADC_FIFOC (0x10)
131#define SUN6I_CODEC_ADC_FIFOC_EN_AD (28)
132#define SUN6I_CODEC_ADC_FIFOS (0x14)
133#define SUN6I_CODEC_ADC_RXDATA (0x18)
134
135/* Output mixer and gain controls */
136#define SUN6I_CODEC_OM_DACA_CTRL (0x20)
137#define SUN6I_CODEC_OM_DACA_CTRL_DACAREN (31)
138#define SUN6I_CODEC_OM_DACA_CTRL_DACALEN (30)
139#define SUN6I_CODEC_OM_DACA_CTRL_RMIXEN (29)
140#define SUN6I_CODEC_OM_DACA_CTRL_LMIXEN (28)
141#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_MIC1 (23)
142#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_MIC2 (22)
143#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_PHONE (21)
144#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_PHONEP (20)
145#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_LINEINR (19)
146#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_DACR (18)
147#define SUN6I_CODEC_OM_DACA_CTRL_RMIX_DACL (17)
148#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_MIC1 (16)
149#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_MIC2 (15)
150#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_PHONE (14)
151#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_PHONEN (13)
152#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_LINEINL (12)
153#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_DACL (11)
154#define SUN6I_CODEC_OM_DACA_CTRL_LMIX_DACR (10)
155#define SUN6I_CODEC_OM_DACA_CTRL_RHPIS (9)
156#define SUN6I_CODEC_OM_DACA_CTRL_LHPIS (8)
157#define SUN6I_CODEC_OM_DACA_CTRL_RHPPAMUTE (7)
158#define SUN6I_CODEC_OM_DACA_CTRL_LHPPAMUTE (6)
159#define SUN6I_CODEC_OM_DACA_CTRL_HPVOL (0)
160#define SUN6I_CODEC_OM_PA_CTRL (0x24)
161#define SUN6I_CODEC_OM_PA_CTRL_HPPAEN (31)
162#define SUN6I_CODEC_OM_PA_CTRL_HPCOM_CTL (29)
163#define SUN6I_CODEC_OM_PA_CTRL_COMPTEN (28)
164#define SUN6I_CODEC_OM_PA_CTRL_MIC1G (15)
165#define SUN6I_CODEC_OM_PA_CTRL_MIC2G (12)
166#define SUN6I_CODEC_OM_PA_CTRL_LINEING (9)
167#define SUN6I_CODEC_OM_PA_CTRL_PHONEG (6)
168#define SUN6I_CODEC_OM_PA_CTRL_PHONEPG (3)
169#define SUN6I_CODEC_OM_PA_CTRL_PHONENG (0)
170
171/* Microphone, line out and phone out controls */
172#define SUN6I_CODEC_MIC_CTRL (0x28)
173#define SUN6I_CODEC_MIC_CTRL_HBIASEN (31)
174#define SUN6I_CODEC_MIC_CTRL_MBIASEN (30)
175#define SUN6I_CODEC_MIC_CTRL_MIC1AMPEN (28)
176#define SUN6I_CODEC_MIC_CTRL_MIC1BOOST (25)
177#define SUN6I_CODEC_MIC_CTRL_MIC2AMPEN (24)
178#define SUN6I_CODEC_MIC_CTRL_MIC2BOOST (21)
179#define SUN6I_CODEC_MIC_CTRL_MIC2SLT (20)
180#define SUN6I_CODEC_MIC_CTRL_LINEOUTLEN (19)
181#define SUN6I_CODEC_MIC_CTRL_LINEOUTREN (18)
182#define SUN6I_CODEC_MIC_CTRL_LINEOUTLSRC (17)
183#define SUN6I_CODEC_MIC_CTRL_LINEOUTRSRC (16)
184#define SUN6I_CODEC_MIC_CTRL_LINEOUTVC (11)
185#define SUN6I_CODEC_MIC_CTRL_PHONEPREG (8)
186
187/* ADC mixer controls */
188#define SUN6I_CODEC_ADC_ACTL (0x2c)
189#define SUN6I_CODEC_ADC_ACTL_ADCREN (31)
190#define SUN6I_CODEC_ADC_ACTL_ADCLEN (30)
191#define SUN6I_CODEC_ADC_ACTL_ADCRG (27)
192#define SUN6I_CODEC_ADC_ACTL_ADCLG (24)
193#define SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC1 (13)
194#define SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC2 (12)
195#define SUN6I_CODEC_ADC_ACTL_RADCMIX_PHONE (11)
196#define SUN6I_CODEC_ADC_ACTL_RADCMIX_PHONEP (10)
197#define SUN6I_CODEC_ADC_ACTL_RADCMIX_LINEINR (9)
198#define SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXR (8)
199#define SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXL (7)
200#define SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC1 (6)
201#define SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC2 (5)
202#define SUN6I_CODEC_ADC_ACTL_LADCMIX_PHONE (4)
203#define SUN6I_CODEC_ADC_ACTL_LADCMIX_PHONEN (3)
204#define SUN6I_CODEC_ADC_ACTL_LADCMIX_LINEINL (2)
205#define SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXL (1)
206#define SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXR (0)
207
208/* Analog performance tuning controls */
209#define SUN6I_CODEC_ADDA_TUNE (0x30)
210
211/* Calibration controls */
212#define SUN6I_CODEC_CALIBRATION (0x34)
213
214/* FIFO counters */
215#define SUN6I_CODEC_DAC_TXCNT (0x40)
216#define SUN6I_CODEC_ADC_RXCNT (0x44)
217
218/* headset jack detection and button support registers */
219#define SUN6I_CODEC_HMIC_CTL (0x50)
220#define SUN6I_CODEC_HMIC_DATA (0x54)
221
222/* TODO sun6i DAP (Digital Audio Processing) bits */
223
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +0800224/* FIFO counters moved on A23 */
225#define SUN8I_A23_CODEC_DAC_TXCNT (0x1c)
226#define SUN8I_A23_CODEC_ADC_RXCNT (0x20)
227
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +0800228/* TX FIFO moved on H3 */
229#define SUN8I_H3_CODEC_DAC_TXDATA (0x20)
230#define SUN8I_H3_CODEC_DAC_DBG (0x48)
231#define SUN8I_H3_CODEC_ADC_DBG (0x4c)
232
233/* TODO H3 DAP (Digital Audio Processing) bits */
234
Emilio López45fb6b62015-09-12 15:26:24 +0200235struct sun4i_codec {
236 struct device *dev;
237 struct regmap *regmap;
238 struct clk *clk_apb;
239 struct clk *clk_module;
Chen-Yu Tsai9aead152016-11-07 18:06:58 +0800240 struct reset_control *rst;
Hans de Goede40592622015-12-11 19:43:57 +0100241 struct gpio_desc *gpio_pa;
Emilio López45fb6b62015-09-12 15:26:24 +0200242
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800243 /* ADC_FIFOC register is at different offset on different SoCs */
244 struct regmap_field *reg_adc_fifoc;
245
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100246 struct snd_dmaengine_dai_dma_data capture_dma_data;
Emilio López45fb6b62015-09-12 15:26:24 +0200247 struct snd_dmaengine_dai_dma_data playback_dma_data;
248};
249
250static void sun4i_codec_start_playback(struct sun4i_codec *scodec)
251{
Emilio López45fb6b62015-09-12 15:26:24 +0200252 /* Flush TX FIFO */
253 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
254 BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH),
255 BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH));
256
257 /* Enable DAC DRQ */
258 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
259 BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN),
260 BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN));
261}
262
263static void sun4i_codec_stop_playback(struct sun4i_codec *scodec)
264{
Emilio López45fb6b62015-09-12 15:26:24 +0200265 /* Disable DAC DRQ */
266 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
267 BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN),
268 0);
269}
270
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100271static void sun4i_codec_start_capture(struct sun4i_codec *scodec)
272{
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100273 /* Enable ADC DRQ */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800274 regmap_field_update_bits(scodec->reg_adc_fifoc,
275 BIT(SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN),
276 BIT(SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN));
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100277}
278
279static void sun4i_codec_stop_capture(struct sun4i_codec *scodec)
280{
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100281 /* Disable ADC DRQ */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800282 regmap_field_update_bits(scodec->reg_adc_fifoc,
283 BIT(SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN), 0);
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100284}
285
Emilio López45fb6b62015-09-12 15:26:24 +0200286static int sun4i_codec_trigger(struct snd_pcm_substream *substream, int cmd,
287 struct snd_soc_dai *dai)
288{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900289 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Emilio López45fb6b62015-09-12 15:26:24 +0200290 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
291
Emilio López45fb6b62015-09-12 15:26:24 +0200292 switch (cmd) {
293 case SNDRV_PCM_TRIGGER_START:
294 case SNDRV_PCM_TRIGGER_RESUME:
295 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100296 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
297 sun4i_codec_start_playback(scodec);
298 else
299 sun4i_codec_start_capture(scodec);
Emilio López45fb6b62015-09-12 15:26:24 +0200300 break;
301
302 case SNDRV_PCM_TRIGGER_STOP:
303 case SNDRV_PCM_TRIGGER_SUSPEND:
304 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100305 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
306 sun4i_codec_stop_playback(scodec);
307 else
308 sun4i_codec_stop_capture(scodec);
Emilio López45fb6b62015-09-12 15:26:24 +0200309 break;
310
311 default:
312 return -EINVAL;
313 }
314
315 return 0;
316}
317
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100318static int sun4i_codec_prepare_capture(struct snd_pcm_substream *substream,
319 struct snd_soc_dai *dai)
320{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900321 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100322 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
323
324
325 /* Flush RX FIFO */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800326 regmap_field_update_bits(scodec->reg_adc_fifoc,
327 BIT(SUN4I_CODEC_ADC_FIFOC_FIFO_FLUSH),
328 BIT(SUN4I_CODEC_ADC_FIFOC_FIFO_FLUSH));
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100329
330
331 /* Set RX FIFO trigger level */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800332 regmap_field_update_bits(scodec->reg_adc_fifoc,
333 0xf << SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL,
334 0x7 << SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL);
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100335
336 /*
337 * FIXME: Undocumented in the datasheet, but
Randy Dunlap0d8aa2c2020-08-07 18:22:09 -0700338 * Allwinner's code mentions that it is
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100339 * related to microphone gain
340 */
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800341 if (of_device_is_compatible(scodec->dev->of_node,
342 "allwinner,sun4i-a10-codec") ||
343 of_device_is_compatible(scodec->dev->of_node,
344 "allwinner,sun7i-a20-codec")) {
345 regmap_update_bits(scodec->regmap, SUN4I_CODEC_ADC_ACTL,
346 0x3 << 25,
347 0x1 << 25);
348 }
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100349
350 if (of_device_is_compatible(scodec->dev->of_node,
351 "allwinner,sun7i-a20-codec"))
352 /* FIXME: Undocumented bits */
353 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_TUNE,
354 0x3 << 8,
355 0x1 << 8);
356
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100357 return 0;
358}
359
360static int sun4i_codec_prepare_playback(struct snd_pcm_substream *substream,
361 struct snd_soc_dai *dai)
Emilio López45fb6b62015-09-12 15:26:24 +0200362{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900363 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Emilio López45fb6b62015-09-12 15:26:24 +0200364 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
365 u32 val;
366
Emilio López45fb6b62015-09-12 15:26:24 +0200367 /* Flush the TX FIFO */
368 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
369 BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH),
370 BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH));
371
372 /* Set TX FIFO Empty Trigger Level */
373 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
374 0x3f << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL,
375 0xf << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL);
376
377 if (substream->runtime->rate > 32000)
378 /* Use 64 bits FIR filter */
379 val = 0;
380 else
381 /* Use 32 bits FIR filter */
382 val = BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION);
383
384 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
385 BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION),
386 val);
387
388 /* Send zeros when we have an underrun */
389 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
390 BIT(SUN4I_CODEC_DAC_FIFOC_SEND_LASAT),
391 0);
392
393 return 0;
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100394};
395
396static int sun4i_codec_prepare(struct snd_pcm_substream *substream,
397 struct snd_soc_dai *dai)
398{
399 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
400 return sun4i_codec_prepare_playback(substream, dai);
401
402 return sun4i_codec_prepare_capture(substream, dai);
Emilio López45fb6b62015-09-12 15:26:24 +0200403}
404
405static unsigned long sun4i_codec_get_mod_freq(struct snd_pcm_hw_params *params)
406{
407 unsigned int rate = params_rate(params);
408
409 switch (rate) {
410 case 176400:
411 case 88200:
412 case 44100:
413 case 33075:
414 case 22050:
415 case 14700:
416 case 11025:
417 case 7350:
418 return 22579200;
419
420 case 192000:
421 case 96000:
422 case 48000:
423 case 32000:
424 case 24000:
425 case 16000:
426 case 12000:
427 case 8000:
428 return 24576000;
429
430 default:
431 return 0;
432 }
433}
434
435static int sun4i_codec_get_hw_rate(struct snd_pcm_hw_params *params)
436{
437 unsigned int rate = params_rate(params);
438
439 switch (rate) {
440 case 192000:
441 case 176400:
442 return 6;
443
444 case 96000:
445 case 88200:
446 return 7;
447
448 case 48000:
449 case 44100:
450 return 0;
451
452 case 32000:
453 case 33075:
454 return 1;
455
456 case 24000:
457 case 22050:
458 return 2;
459
460 case 16000:
461 case 14700:
462 return 3;
463
464 case 12000:
465 case 11025:
466 return 4;
467
468 case 8000:
469 case 7350:
470 return 5;
471
472 default:
473 return -EINVAL;
474 }
475}
476
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100477static int sun4i_codec_hw_params_capture(struct sun4i_codec *scodec,
478 struct snd_pcm_hw_params *params,
479 unsigned int hwrate)
Emilio López45fb6b62015-09-12 15:26:24 +0200480{
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100481 /* Set ADC sample rate */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800482 regmap_field_update_bits(scodec->reg_adc_fifoc,
483 7 << SUN4I_CODEC_ADC_FIFOC_ADC_FS,
484 hwrate << SUN4I_CODEC_ADC_FIFOC_ADC_FS);
Emilio López45fb6b62015-09-12 15:26:24 +0200485
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100486 /* Set the number of channels we want to use */
487 if (params_channels(params) == 1)
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800488 regmap_field_update_bits(scodec->reg_adc_fifoc,
489 BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN),
490 BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN));
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100491 else
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +0800492 regmap_field_update_bits(scodec->reg_adc_fifoc,
493 BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN),
494 0);
Emilio López45fb6b62015-09-12 15:26:24 +0200495
Andrea Bondavalli8a0f95c2017-10-31 12:58:18 +0100496 /* Set the number of sample bits to either 16 or 24 bits */
497 if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) {
498 regmap_field_update_bits(scodec->reg_adc_fifoc,
499 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS),
500 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS));
501
502 regmap_field_update_bits(scodec->reg_adc_fifoc,
503 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE),
504 0);
505
506 scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
507 } else {
508 regmap_field_update_bits(scodec->reg_adc_fifoc,
509 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS),
510 0);
511
512 /* Fill most significant bits with valid data MSB */
513 regmap_field_update_bits(scodec->reg_adc_fifoc,
514 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE),
515 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE));
516
517 scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
518 }
519
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100520 return 0;
521}
Emilio López45fb6b62015-09-12 15:26:24 +0200522
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100523static int sun4i_codec_hw_params_playback(struct sun4i_codec *scodec,
524 struct snd_pcm_hw_params *params,
525 unsigned int hwrate)
526{
527 u32 val;
Emilio López45fb6b62015-09-12 15:26:24 +0200528
529 /* Set DAC sample rate */
530 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
531 7 << SUN4I_CODEC_DAC_FIFOC_DAC_FS,
532 hwrate << SUN4I_CODEC_DAC_FIFOC_DAC_FS);
533
534 /* Set the number of channels we want to use */
535 if (params_channels(params) == 1)
536 val = BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN);
537 else
538 val = 0;
539
540 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
541 BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN),
542 val);
543
544 /* Set the number of sample bits to either 16 or 24 bits */
545 if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) {
546 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
547 BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS),
548 BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS));
549
550 /* Set TX FIFO mode to padding the LSBs with 0 */
551 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
552 BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE),
553 0);
554
555 scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
556 } else {
557 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
558 BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS),
559 0);
560
561 /* Set TX FIFO mode to repeat the MSB */
562 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
563 BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE),
564 BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE));
565
566 scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
567 }
568
569 return 0;
570}
571
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100572static int sun4i_codec_hw_params(struct snd_pcm_substream *substream,
573 struct snd_pcm_hw_params *params,
574 struct snd_soc_dai *dai)
575{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900576 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100577 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
578 unsigned long clk_freq;
Maxime Ripard8400ddf2015-12-01 12:06:47 +0100579 int ret, hwrate;
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100580
581 clk_freq = sun4i_codec_get_mod_freq(params);
582 if (!clk_freq)
583 return -EINVAL;
584
Maxime Ripard8400ddf2015-12-01 12:06:47 +0100585 ret = clk_set_rate(scodec->clk_module, clk_freq);
586 if (ret)
587 return ret;
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100588
589 hwrate = sun4i_codec_get_hw_rate(params);
590 if (hwrate < 0)
591 return hwrate;
592
593 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
594 return sun4i_codec_hw_params_playback(scodec, params,
595 hwrate);
596
597 return sun4i_codec_hw_params_capture(scodec, params,
598 hwrate);
599}
600
Andrea Bondavalli5a0cf022017-12-12 10:14:50 +0100601
602static unsigned int sun4i_codec_src_rates[] = {
603 8000, 11025, 12000, 16000, 22050, 24000, 32000,
604 44100, 48000, 96000, 192000
605};
606
607
608static struct snd_pcm_hw_constraint_list sun4i_codec_constraints = {
609 .count = ARRAY_SIZE(sun4i_codec_src_rates),
610 .list = sun4i_codec_src_rates,
611};
612
613
Emilio López45fb6b62015-09-12 15:26:24 +0200614static int sun4i_codec_startup(struct snd_pcm_substream *substream,
615 struct snd_soc_dai *dai)
616{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900617 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Emilio López45fb6b62015-09-12 15:26:24 +0200618 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
619
Andrea Bondavalli5a0cf022017-12-12 10:14:50 +0100620 snd_pcm_hw_constraint_list(substream->runtime, 0,
621 SNDRV_PCM_HW_PARAM_RATE, &sun4i_codec_constraints);
622
Emilio López45fb6b62015-09-12 15:26:24 +0200623 /*
624 * Stop issuing DRQ when we have room for less than 16 samples
625 * in our TX FIFO
626 */
627 regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC,
628 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT,
629 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT);
630
631 return clk_prepare_enable(scodec->clk_module);
632}
633
634static void sun4i_codec_shutdown(struct snd_pcm_substream *substream,
635 struct snd_soc_dai *dai)
636{
Kuninori Morimotoc09e34b2020-07-20 10:17:57 +0900637 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Emilio López45fb6b62015-09-12 15:26:24 +0200638 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card);
639
640 clk_disable_unprepare(scodec->clk_module);
641}
642
643static const struct snd_soc_dai_ops sun4i_codec_dai_ops = {
644 .startup = sun4i_codec_startup,
645 .shutdown = sun4i_codec_shutdown,
646 .trigger = sun4i_codec_trigger,
647 .hw_params = sun4i_codec_hw_params,
648 .prepare = sun4i_codec_prepare,
649};
650
651static struct snd_soc_dai_driver sun4i_codec_dai = {
652 .name = "Codec",
653 .ops = &sun4i_codec_dai_ops,
654 .playback = {
655 .stream_name = "Codec Playback",
656 .channels_min = 1,
657 .channels_max = 2,
658 .rate_min = 8000,
659 .rate_max = 192000,
Andrea Bondavalli5a0cf022017-12-12 10:14:50 +0100660 .rates = SNDRV_PCM_RATE_CONTINUOUS,
Emilio López45fb6b62015-09-12 15:26:24 +0200661 .formats = SNDRV_PCM_FMTBIT_S16_LE |
662 SNDRV_PCM_FMTBIT_S32_LE,
663 .sig_bits = 24,
664 },
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100665 .capture = {
666 .stream_name = "Codec Capture",
667 .channels_min = 1,
668 .channels_max = 2,
669 .rate_min = 8000,
Andrea Bondavalli5a0cf022017-12-12 10:14:50 +0100670 .rate_max = 48000,
671 .rates = SNDRV_PCM_RATE_CONTINUOUS,
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100672 .formats = SNDRV_PCM_FMTBIT_S16_LE |
673 SNDRV_PCM_FMTBIT_S32_LE,
674 .sig_bits = 24,
675 },
Emilio López45fb6b62015-09-12 15:26:24 +0200676};
677
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800678/*** sun4i Codec ***/
Emilio López45fb6b62015-09-12 15:26:24 +0200679static const struct snd_kcontrol_new sun4i_codec_pa_mute =
680 SOC_DAPM_SINGLE("Switch", SUN4I_CODEC_DAC_ACTL,
681 SUN4I_CODEC_DAC_ACTL_PA_MUTE, 1, 0);
682
683static DECLARE_TLV_DB_SCALE(sun4i_codec_pa_volume_scale, -6300, 100, 1);
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100684static DECLARE_TLV_DB_SCALE(sun4i_codec_linein_loopback_gain_scale, -150, 150,
685 0);
686static DECLARE_TLV_DB_SCALE(sun4i_codec_linein_preamp_gain_scale, -1200, 300,
687 0);
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100688static DECLARE_TLV_DB_SCALE(sun4i_codec_fmin_loopback_gain_scale, -450, 150,
689 0);
Danny Milosavljevic63bd8482019-01-30 11:39:37 +0100690static DECLARE_TLV_DB_SCALE(sun4i_codec_micin_loopback_gain_scale, -450, 150,
691 0);
Danny Milosavljevicb329c782019-01-30 11:39:40 +0100692static DECLARE_TLV_DB_RANGE(sun4i_codec_micin_preamp_gain_scale,
693 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
694 1, 7, TLV_DB_SCALE_ITEM(3500, 300, 0));
695static DECLARE_TLV_DB_RANGE(sun7i_codec_micin_preamp_gain_scale,
696 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
697 1, 7, TLV_DB_SCALE_ITEM(2400, 300, 0));
Emilio López45fb6b62015-09-12 15:26:24 +0200698
Danny Milosavljevicc9e902f2016-09-24 22:05:01 +0200699static const struct snd_kcontrol_new sun4i_codec_controls[] = {
Adam Sampson474d1472015-10-27 21:00:45 +0000700 SOC_SINGLE_TLV("Power Amplifier Volume", SUN4I_CODEC_DAC_ACTL,
Emilio López45fb6b62015-09-12 15:26:24 +0200701 SUN4I_CODEC_DAC_ACTL_PA_VOL, 0x3F, 0,
702 sun4i_codec_pa_volume_scale),
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100703 SOC_SINGLE_TLV("Line Playback Volume", SUN4I_CODEC_DAC_ACTL,
704 SUN4I_CODEC_DAC_ACTL_LNG, 1, 0,
705 sun4i_codec_linein_loopback_gain_scale),
706 SOC_SINGLE_TLV("Line Boost Volume", SUN4I_CODEC_ADC_ACTL,
707 SUN4I_CODEC_ADC_ACTL_LNPREG, 7, 0,
708 sun4i_codec_linein_preamp_gain_scale),
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100709 SOC_SINGLE_TLV("FM Playback Volume", SUN4I_CODEC_DAC_ACTL,
710 SUN4I_CODEC_DAC_ACTL_FMG, 3, 0,
711 sun4i_codec_fmin_loopback_gain_scale),
Danny Milosavljevicb5a65602019-01-30 11:39:38 +0100712 SOC_SINGLE_TLV("Mic Playback Volume", SUN4I_CODEC_DAC_ACTL,
713 SUN4I_CODEC_DAC_ACTL_MICG, 7, 0,
714 sun4i_codec_micin_loopback_gain_scale),
Danny Milosavljevicb329c782019-01-30 11:39:40 +0100715 SOC_SINGLE_TLV("Mic1 Boost Volume", SUN4I_CODEC_ADC_ACTL,
716 SUN4I_CODEC_ADC_ACTL_PREG1, 3, 0,
717 sun4i_codec_micin_preamp_gain_scale),
718 SOC_SINGLE_TLV("Mic2 Boost Volume", SUN4I_CODEC_ADC_ACTL,
719 SUN4I_CODEC_ADC_ACTL_PREG2, 3, 0,
720 sun4i_codec_micin_preamp_gain_scale),
Emilio López45fb6b62015-09-12 15:26:24 +0200721};
722
Danny Milosavljevicb71a7eb2019-01-30 11:39:39 +0100723static const struct snd_kcontrol_new sun7i_codec_controls[] = {
724 SOC_SINGLE_TLV("Power Amplifier Volume", SUN4I_CODEC_DAC_ACTL,
725 SUN4I_CODEC_DAC_ACTL_PA_VOL, 0x3F, 0,
726 sun4i_codec_pa_volume_scale),
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100727 SOC_SINGLE_TLV("Line Playback Volume", SUN4I_CODEC_DAC_ACTL,
728 SUN4I_CODEC_DAC_ACTL_LNG, 1, 0,
729 sun4i_codec_linein_loopback_gain_scale),
730 SOC_SINGLE_TLV("Line Boost Volume", SUN4I_CODEC_ADC_ACTL,
731 SUN4I_CODEC_ADC_ACTL_LNPREG, 7, 0,
732 sun4i_codec_linein_preamp_gain_scale),
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100733 SOC_SINGLE_TLV("FM Playback Volume", SUN4I_CODEC_DAC_ACTL,
734 SUN4I_CODEC_DAC_ACTL_FMG, 3, 0,
735 sun4i_codec_fmin_loopback_gain_scale),
Danny Milosavljevicb71a7eb2019-01-30 11:39:39 +0100736 SOC_SINGLE_TLV("Mic Playback Volume", SUN4I_CODEC_DAC_ACTL,
737 SUN4I_CODEC_DAC_ACTL_MICG, 7, 0,
738 sun4i_codec_micin_loopback_gain_scale),
Danny Milosavljevicb329c782019-01-30 11:39:40 +0100739 SOC_SINGLE_TLV("Mic1 Boost Volume", SUN7I_CODEC_AC_MIC_PHONE_CAL,
740 SUN7I_CODEC_AC_MIC_PHONE_CAL_PREG1, 7, 0,
741 sun7i_codec_micin_preamp_gain_scale),
742 SOC_SINGLE_TLV("Mic2 Boost Volume", SUN7I_CODEC_AC_MIC_PHONE_CAL,
743 SUN7I_CODEC_AC_MIC_PHONE_CAL_PREG2, 7, 0,
744 sun7i_codec_micin_preamp_gain_scale),
Danny Milosavljevicb71a7eb2019-01-30 11:39:39 +0100745};
746
Danny Milosavljevic0bbb8e82019-01-30 11:39:41 +0100747static const struct snd_kcontrol_new sun4i_codec_mixer_controls[] = {
748 SOC_DAPM_SINGLE("Left Mixer Left DAC Playback Switch",
749 SUN4I_CODEC_DAC_ACTL, SUN4I_CODEC_DAC_ACTL_LDACLMIXS,
750 1, 0),
751 SOC_DAPM_SINGLE("Right Mixer Right DAC Playback Switch",
752 SUN4I_CODEC_DAC_ACTL, SUN4I_CODEC_DAC_ACTL_RDACRMIXS,
753 1, 0),
754 SOC_DAPM_SINGLE("Right Mixer Left DAC Playback Switch",
755 SUN4I_CODEC_DAC_ACTL,
Emilio López45fb6b62015-09-12 15:26:24 +0200756 SUN4I_CODEC_DAC_ACTL_LDACRMIXS, 1, 0),
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100757 SOC_DAPM_DOUBLE("Line Playback Switch", SUN4I_CODEC_DAC_ACTL,
758 SUN4I_CODEC_DAC_ACTL_LLNS,
759 SUN4I_CODEC_DAC_ACTL_RLNS, 1, 0),
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100760 SOC_DAPM_DOUBLE("FM Playback Switch", SUN4I_CODEC_DAC_ACTL,
761 SUN4I_CODEC_DAC_ACTL_LFMS,
762 SUN4I_CODEC_DAC_ACTL_RFMS, 1, 0),
Danny Milosavljevic44a1f4e2019-01-30 11:39:42 +0100763 SOC_DAPM_DOUBLE("Mic1 Playback Switch", SUN4I_CODEC_DAC_ACTL,
764 SUN4I_CODEC_DAC_ACTL_MIC1LS,
765 SUN4I_CODEC_DAC_ACTL_MIC1RS, 1, 0),
766 SOC_DAPM_DOUBLE("Mic2 Playback Switch", SUN4I_CODEC_DAC_ACTL,
767 SUN4I_CODEC_DAC_ACTL_MIC2LS,
768 SUN4I_CODEC_DAC_ACTL_MIC2RS, 1, 0),
Emilio López45fb6b62015-09-12 15:26:24 +0200769};
770
771static const struct snd_kcontrol_new sun4i_codec_pa_mixer_controls[] = {
772 SOC_DAPM_SINGLE("DAC Playback Switch", SUN4I_CODEC_DAC_ACTL,
773 SUN4I_CODEC_DAC_ACTL_DACPAS, 1, 0),
774 SOC_DAPM_SINGLE("Mixer Playback Switch", SUN4I_CODEC_DAC_ACTL,
775 SUN4I_CODEC_DAC_ACTL_MIXPAS, 1, 0),
776};
777
Hans de Goedee6415b42015-12-11 19:43:56 +0100778static const struct snd_soc_dapm_widget sun4i_codec_codec_dapm_widgets[] = {
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100779 /* Digital parts of the ADCs */
780 SND_SOC_DAPM_SUPPLY("ADC", SUN4I_CODEC_ADC_FIFOC,
781 SUN4I_CODEC_ADC_FIFOC_EN_AD, 0,
782 NULL, 0),
783
Emilio López45fb6b62015-09-12 15:26:24 +0200784 /* Digital parts of the DACs */
785 SND_SOC_DAPM_SUPPLY("DAC", SUN4I_CODEC_DAC_DPC,
786 SUN4I_CODEC_DAC_DPC_EN_DA, 0,
787 NULL, 0),
788
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100789 /* Analog parts of the ADCs */
790 SND_SOC_DAPM_ADC("Left ADC", "Codec Capture", SUN4I_CODEC_ADC_ACTL,
791 SUN4I_CODEC_ADC_ACTL_ADC_L_EN, 0),
792 SND_SOC_DAPM_ADC("Right ADC", "Codec Capture", SUN4I_CODEC_ADC_ACTL,
793 SUN4I_CODEC_ADC_ACTL_ADC_R_EN, 0),
794
Emilio López45fb6b62015-09-12 15:26:24 +0200795 /* Analog parts of the DACs */
796 SND_SOC_DAPM_DAC("Left DAC", "Codec Playback", SUN4I_CODEC_DAC_ACTL,
797 SUN4I_CODEC_DAC_ACTL_DACAENL, 0),
798 SND_SOC_DAPM_DAC("Right DAC", "Codec Playback", SUN4I_CODEC_DAC_ACTL,
799 SUN4I_CODEC_DAC_ACTL_DACAENR, 0),
800
801 /* Mixers */
802 SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0,
Danny Milosavljevic0bbb8e82019-01-30 11:39:41 +0100803 sun4i_codec_mixer_controls,
804 ARRAY_SIZE(sun4i_codec_mixer_controls)),
Emilio López45fb6b62015-09-12 15:26:24 +0200805 SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0,
Danny Milosavljevic0bbb8e82019-01-30 11:39:41 +0100806 sun4i_codec_mixer_controls,
807 ARRAY_SIZE(sun4i_codec_mixer_controls)),
Emilio López45fb6b62015-09-12 15:26:24 +0200808
809 /* Global Mixer Enable */
810 SND_SOC_DAPM_SUPPLY("Mixer Enable", SUN4I_CODEC_DAC_ACTL,
811 SUN4I_CODEC_DAC_ACTL_MIXEN, 0, NULL, 0),
812
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100813 /* VMIC */
814 SND_SOC_DAPM_SUPPLY("VMIC", SUN4I_CODEC_ADC_ACTL,
815 SUN4I_CODEC_ADC_ACTL_VMICEN, 0, NULL, 0),
816
817 /* Mic Pre-Amplifiers */
818 SND_SOC_DAPM_PGA("MIC1 Pre-Amplifier", SUN4I_CODEC_ADC_ACTL,
819 SUN4I_CODEC_ADC_ACTL_PREG1EN, 0, NULL, 0),
Danny Milosavljevic63bd8482019-01-30 11:39:37 +0100820 SND_SOC_DAPM_PGA("MIC2 Pre-Amplifier", SUN4I_CODEC_ADC_ACTL,
821 SUN4I_CODEC_ADC_ACTL_PREG2EN, 0, NULL, 0),
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100822
Adam Sampson474d1472015-10-27 21:00:45 +0000823 /* Power Amplifier */
824 SND_SOC_DAPM_MIXER("Power Amplifier", SUN4I_CODEC_ADC_ACTL,
Emilio López45fb6b62015-09-12 15:26:24 +0200825 SUN4I_CODEC_ADC_ACTL_PA_EN, 0,
826 sun4i_codec_pa_mixer_controls,
827 ARRAY_SIZE(sun4i_codec_pa_mixer_controls)),
Adam Sampson474d1472015-10-27 21:00:45 +0000828 SND_SOC_DAPM_SWITCH("Power Amplifier Mute", SND_SOC_NOPM, 0, 0,
Emilio López45fb6b62015-09-12 15:26:24 +0200829 &sun4i_codec_pa_mute),
830
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100831 SND_SOC_DAPM_INPUT("Line Right"),
832 SND_SOC_DAPM_INPUT("Line Left"),
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100833 SND_SOC_DAPM_INPUT("FM Right"),
834 SND_SOC_DAPM_INPUT("FM Left"),
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100835 SND_SOC_DAPM_INPUT("Mic1"),
Danny Milosavljevic63bd8482019-01-30 11:39:37 +0100836 SND_SOC_DAPM_INPUT("Mic2"),
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100837
Emilio López45fb6b62015-09-12 15:26:24 +0200838 SND_SOC_DAPM_OUTPUT("HP Right"),
839 SND_SOC_DAPM_OUTPUT("HP Left"),
840};
841
Hans de Goedee6415b42015-12-11 19:43:56 +0100842static const struct snd_soc_dapm_route sun4i_codec_codec_dapm_routes[] = {
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100843 /* Left ADC / DAC Routes */
844 { "Left ADC", NULL, "ADC" },
Emilio López45fb6b62015-09-12 15:26:24 +0200845 { "Left DAC", NULL, "DAC" },
846
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100847 /* Right ADC / DAC Routes */
848 { "Right ADC", NULL, "ADC" },
Emilio López45fb6b62015-09-12 15:26:24 +0200849 { "Right DAC", NULL, "DAC" },
850
851 /* Right Mixer Routes */
852 { "Right Mixer", NULL, "Mixer Enable" },
Danny Milosavljevic0bbb8e82019-01-30 11:39:41 +0100853 { "Right Mixer", "Right Mixer Left DAC Playback Switch", "Left DAC" },
854 { "Right Mixer", "Right Mixer Right DAC Playback Switch", "Right DAC" },
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100855 { "Right Mixer", "Line Playback Switch", "Line Right" },
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100856 { "Right Mixer", "FM Playback Switch", "FM Right" },
Danny Milosavljevic44a1f4e2019-01-30 11:39:42 +0100857 { "Right Mixer", "Mic1 Playback Switch", "MIC1 Pre-Amplifier" },
858 { "Right Mixer", "Mic2 Playback Switch", "MIC2 Pre-Amplifier" },
Emilio López45fb6b62015-09-12 15:26:24 +0200859
860 /* Left Mixer Routes */
861 { "Left Mixer", NULL, "Mixer Enable" },
Danny Milosavljevic0bbb8e82019-01-30 11:39:41 +0100862 { "Left Mixer", "Left Mixer Left DAC Playback Switch", "Left DAC" },
Danny Milosavljevic67690c22019-01-30 11:39:44 +0100863 { "Left Mixer", "Line Playback Switch", "Line Left" },
Danny Milosavljevic50d16412019-01-30 11:39:43 +0100864 { "Left Mixer", "FM Playback Switch", "FM Left" },
Danny Milosavljevic44a1f4e2019-01-30 11:39:42 +0100865 { "Left Mixer", "Mic1 Playback Switch", "MIC1 Pre-Amplifier" },
866 { "Left Mixer", "Mic2 Playback Switch", "MIC2 Pre-Amplifier" },
Emilio López45fb6b62015-09-12 15:26:24 +0200867
Adam Sampson474d1472015-10-27 21:00:45 +0000868 /* Power Amplifier Routes */
869 { "Power Amplifier", "Mixer Playback Switch", "Left Mixer" },
870 { "Power Amplifier", "Mixer Playback Switch", "Right Mixer" },
871 { "Power Amplifier", "DAC Playback Switch", "Left DAC" },
872 { "Power Amplifier", "DAC Playback Switch", "Right DAC" },
Emilio López45fb6b62015-09-12 15:26:24 +0200873
Adam Sampson474d1472015-10-27 21:00:45 +0000874 /* Headphone Output Routes */
875 { "Power Amplifier Mute", "Switch", "Power Amplifier" },
876 { "HP Right", NULL, "Power Amplifier Mute" },
877 { "HP Left", NULL, "Power Amplifier Mute" },
Maxime Ripard1fb34b42015-11-30 16:37:47 +0100878
879 /* Mic1 Routes */
880 { "Left ADC", NULL, "MIC1 Pre-Amplifier" },
881 { "Right ADC", NULL, "MIC1 Pre-Amplifier" },
882 { "MIC1 Pre-Amplifier", NULL, "Mic1"},
883 { "Mic1", NULL, "VMIC" },
Danny Milosavljevic63bd8482019-01-30 11:39:37 +0100884
885 /* Mic2 Routes */
886 { "Left ADC", NULL, "MIC2 Pre-Amplifier" },
887 { "Right ADC", NULL, "MIC2 Pre-Amplifier" },
888 { "MIC2 Pre-Amplifier", NULL, "Mic2"},
889 { "Mic2", NULL, "VMIC" },
Emilio López45fb6b62015-09-12 15:26:24 +0200890};
891
Kuninori Morimoto77f4be162018-01-29 04:23:46 +0000892static const struct snd_soc_component_driver sun4i_codec_codec = {
893 .controls = sun4i_codec_controls,
894 .num_controls = ARRAY_SIZE(sun4i_codec_controls),
895 .dapm_widgets = sun4i_codec_codec_dapm_widgets,
896 .num_dapm_widgets = ARRAY_SIZE(sun4i_codec_codec_dapm_widgets),
897 .dapm_routes = sun4i_codec_codec_dapm_routes,
898 .num_dapm_routes = ARRAY_SIZE(sun4i_codec_codec_dapm_routes),
899 .idle_bias_on = 1,
900 .use_pmdown_time = 1,
901 .endianness = 1,
902 .non_legacy_dai_naming = 1,
Emilio López45fb6b62015-09-12 15:26:24 +0200903};
904
Danny Milosavljevicb71a7eb2019-01-30 11:39:39 +0100905static const struct snd_soc_component_driver sun7i_codec_codec = {
906 .controls = sun7i_codec_controls,
907 .num_controls = ARRAY_SIZE(sun7i_codec_controls),
908 .dapm_widgets = sun4i_codec_codec_dapm_widgets,
909 .num_dapm_widgets = ARRAY_SIZE(sun4i_codec_codec_dapm_widgets),
910 .dapm_routes = sun4i_codec_codec_dapm_routes,
911 .num_dapm_routes = ARRAY_SIZE(sun4i_codec_codec_dapm_routes),
912 .idle_bias_on = 1,
913 .use_pmdown_time = 1,
914 .endianness = 1,
915 .non_legacy_dai_naming = 1,
916};
917
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800918/*** sun6i Codec ***/
919
920/* mixer controls */
921static const struct snd_kcontrol_new sun6i_codec_mixer_controls[] = {
922 SOC_DAPM_DOUBLE("DAC Playback Switch",
923 SUN6I_CODEC_OM_DACA_CTRL,
924 SUN6I_CODEC_OM_DACA_CTRL_LMIX_DACL,
925 SUN6I_CODEC_OM_DACA_CTRL_RMIX_DACR, 1, 0),
926 SOC_DAPM_DOUBLE("DAC Reversed Playback Switch",
927 SUN6I_CODEC_OM_DACA_CTRL,
928 SUN6I_CODEC_OM_DACA_CTRL_LMIX_DACR,
929 SUN6I_CODEC_OM_DACA_CTRL_RMIX_DACL, 1, 0),
Chen-Yu Tsaidff50512016-11-03 15:55:49 +0800930 SOC_DAPM_DOUBLE("Line In Playback Switch",
931 SUN6I_CODEC_OM_DACA_CTRL,
932 SUN6I_CODEC_OM_DACA_CTRL_LMIX_LINEINL,
933 SUN6I_CODEC_OM_DACA_CTRL_RMIX_LINEINR, 1, 0),
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +0800934 SOC_DAPM_DOUBLE("Mic1 Playback Switch",
935 SUN6I_CODEC_OM_DACA_CTRL,
936 SUN6I_CODEC_OM_DACA_CTRL_LMIX_MIC1,
937 SUN6I_CODEC_OM_DACA_CTRL_RMIX_MIC1, 1, 0),
938 SOC_DAPM_DOUBLE("Mic2 Playback Switch",
939 SUN6I_CODEC_OM_DACA_CTRL,
940 SUN6I_CODEC_OM_DACA_CTRL_LMIX_MIC2,
941 SUN6I_CODEC_OM_DACA_CTRL_RMIX_MIC2, 1, 0),
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800942};
943
Chen-Yu Tsai24c99f82016-11-07 18:06:59 +0800944/* ADC mixer controls */
945static const struct snd_kcontrol_new sun6i_codec_adc_mixer_controls[] = {
946 SOC_DAPM_DOUBLE("Mixer Capture Switch",
947 SUN6I_CODEC_ADC_ACTL,
948 SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXL,
949 SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXR, 1, 0),
950 SOC_DAPM_DOUBLE("Mixer Reversed Capture Switch",
951 SUN6I_CODEC_ADC_ACTL,
952 SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXR,
953 SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXL, 1, 0),
954 SOC_DAPM_DOUBLE("Line In Capture Switch",
955 SUN6I_CODEC_ADC_ACTL,
956 SUN6I_CODEC_ADC_ACTL_LADCMIX_LINEINL,
957 SUN6I_CODEC_ADC_ACTL_RADCMIX_LINEINR, 1, 0),
958 SOC_DAPM_DOUBLE("Mic1 Capture Switch",
959 SUN6I_CODEC_ADC_ACTL,
960 SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC1,
961 SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC1, 1, 0),
962 SOC_DAPM_DOUBLE("Mic2 Capture Switch",
963 SUN6I_CODEC_ADC_ACTL,
964 SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC2,
965 SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC2, 1, 0),
966};
967
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +0800968/* headphone controls */
969static const char * const sun6i_codec_hp_src_enum_text[] = {
970 "DAC", "Mixer",
971};
972
973static SOC_ENUM_DOUBLE_DECL(sun6i_codec_hp_src_enum,
974 SUN6I_CODEC_OM_DACA_CTRL,
975 SUN6I_CODEC_OM_DACA_CTRL_LHPIS,
976 SUN6I_CODEC_OM_DACA_CTRL_RHPIS,
977 sun6i_codec_hp_src_enum_text);
978
979static const struct snd_kcontrol_new sun6i_codec_hp_src[] = {
980 SOC_DAPM_ENUM("Headphone Source Playback Route",
981 sun6i_codec_hp_src_enum),
982};
983
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +0800984/* microphone controls */
985static const char * const sun6i_codec_mic2_src_enum_text[] = {
986 "Mic2", "Mic3",
987};
988
989static SOC_ENUM_SINGLE_DECL(sun6i_codec_mic2_src_enum,
990 SUN6I_CODEC_MIC_CTRL,
991 SUN6I_CODEC_MIC_CTRL_MIC2SLT,
992 sun6i_codec_mic2_src_enum_text);
993
994static const struct snd_kcontrol_new sun6i_codec_mic2_src[] = {
995 SOC_DAPM_ENUM("Mic2 Amplifier Source Route",
996 sun6i_codec_mic2_src_enum),
997};
998
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +0800999/* line out controls */
1000static const char * const sun6i_codec_lineout_src_enum_text[] = {
1001 "Stereo", "Mono Differential",
1002};
1003
1004static SOC_ENUM_DOUBLE_DECL(sun6i_codec_lineout_src_enum,
1005 SUN6I_CODEC_MIC_CTRL,
1006 SUN6I_CODEC_MIC_CTRL_LINEOUTLSRC,
1007 SUN6I_CODEC_MIC_CTRL_LINEOUTRSRC,
1008 sun6i_codec_lineout_src_enum_text);
1009
1010static const struct snd_kcontrol_new sun6i_codec_lineout_src[] = {
1011 SOC_DAPM_ENUM("Line Out Source Playback Route",
1012 sun6i_codec_lineout_src_enum),
1013};
1014
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001015/* volume / mute controls */
1016static const DECLARE_TLV_DB_SCALE(sun6i_codec_dvol_scale, -7308, 116, 0);
1017static const DECLARE_TLV_DB_SCALE(sun6i_codec_hp_vol_scale, -6300, 100, 1);
Chen-Yu Tsaidff50512016-11-03 15:55:49 +08001018static const DECLARE_TLV_DB_SCALE(sun6i_codec_out_mixer_pregain_scale,
1019 -450, 150, 0);
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001020static const DECLARE_TLV_DB_RANGE(sun6i_codec_lineout_vol_scale,
1021 0, 1, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
1022 2, 31, TLV_DB_SCALE_ITEM(-4350, 150, 0),
1023);
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001024static const DECLARE_TLV_DB_RANGE(sun6i_codec_mic_gain_scale,
1025 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
1026 1, 7, TLV_DB_SCALE_ITEM(2400, 300, 0),
1027);
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001028
1029static const struct snd_kcontrol_new sun6i_codec_codec_widgets[] = {
1030 SOC_SINGLE_TLV("DAC Playback Volume", SUN4I_CODEC_DAC_DPC,
1031 SUN4I_CODEC_DAC_DPC_DVOL, 0x3f, 1,
1032 sun6i_codec_dvol_scale),
1033 SOC_SINGLE_TLV("Headphone Playback Volume",
1034 SUN6I_CODEC_OM_DACA_CTRL,
1035 SUN6I_CODEC_OM_DACA_CTRL_HPVOL, 0x3f, 0,
1036 sun6i_codec_hp_vol_scale),
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001037 SOC_SINGLE_TLV("Line Out Playback Volume",
1038 SUN6I_CODEC_MIC_CTRL,
1039 SUN6I_CODEC_MIC_CTRL_LINEOUTVC, 0x1f, 0,
1040 sun6i_codec_lineout_vol_scale),
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001041 SOC_DOUBLE("Headphone Playback Switch",
1042 SUN6I_CODEC_OM_DACA_CTRL,
1043 SUN6I_CODEC_OM_DACA_CTRL_LHPPAMUTE,
1044 SUN6I_CODEC_OM_DACA_CTRL_RHPPAMUTE, 1, 0),
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001045 SOC_DOUBLE("Line Out Playback Switch",
1046 SUN6I_CODEC_MIC_CTRL,
1047 SUN6I_CODEC_MIC_CTRL_LINEOUTLEN,
1048 SUN6I_CODEC_MIC_CTRL_LINEOUTREN, 1, 0),
Chen-Yu Tsaidff50512016-11-03 15:55:49 +08001049 /* Mixer pre-gains */
1050 SOC_SINGLE_TLV("Line In Playback Volume",
1051 SUN6I_CODEC_OM_PA_CTRL, SUN6I_CODEC_OM_PA_CTRL_LINEING,
1052 0x7, 0, sun6i_codec_out_mixer_pregain_scale),
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001053 SOC_SINGLE_TLV("Mic1 Playback Volume",
1054 SUN6I_CODEC_OM_PA_CTRL, SUN6I_CODEC_OM_PA_CTRL_MIC1G,
1055 0x7, 0, sun6i_codec_out_mixer_pregain_scale),
1056 SOC_SINGLE_TLV("Mic2 Playback Volume",
1057 SUN6I_CODEC_OM_PA_CTRL, SUN6I_CODEC_OM_PA_CTRL_MIC2G,
1058 0x7, 0, sun6i_codec_out_mixer_pregain_scale),
1059
1060 /* Microphone Amp boost gains */
1061 SOC_SINGLE_TLV("Mic1 Boost Volume", SUN6I_CODEC_MIC_CTRL,
1062 SUN6I_CODEC_MIC_CTRL_MIC1BOOST, 0x7, 0,
1063 sun6i_codec_mic_gain_scale),
1064 SOC_SINGLE_TLV("Mic2 Boost Volume", SUN6I_CODEC_MIC_CTRL,
1065 SUN6I_CODEC_MIC_CTRL_MIC2BOOST, 0x7, 0,
1066 sun6i_codec_mic_gain_scale),
Chen-Yu Tsai24c99f82016-11-07 18:06:59 +08001067 SOC_DOUBLE_TLV("ADC Capture Volume",
1068 SUN6I_CODEC_ADC_ACTL, SUN6I_CODEC_ADC_ACTL_ADCLG,
1069 SUN6I_CODEC_ADC_ACTL_ADCRG, 0x7, 0,
1070 sun6i_codec_out_mixer_pregain_scale),
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001071};
1072
1073static const struct snd_soc_dapm_widget sun6i_codec_codec_dapm_widgets[] = {
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001074 /* Microphone inputs */
1075 SND_SOC_DAPM_INPUT("MIC1"),
1076 SND_SOC_DAPM_INPUT("MIC2"),
1077 SND_SOC_DAPM_INPUT("MIC3"),
1078
1079 /* Microphone Bias */
1080 SND_SOC_DAPM_SUPPLY("HBIAS", SUN6I_CODEC_MIC_CTRL,
1081 SUN6I_CODEC_MIC_CTRL_HBIASEN, 0, NULL, 0),
1082 SND_SOC_DAPM_SUPPLY("MBIAS", SUN6I_CODEC_MIC_CTRL,
1083 SUN6I_CODEC_MIC_CTRL_MBIASEN, 0, NULL, 0),
1084
1085 /* Mic input path */
1086 SND_SOC_DAPM_MUX("Mic2 Amplifier Source Route",
1087 SND_SOC_NOPM, 0, 0, sun6i_codec_mic2_src),
1088 SND_SOC_DAPM_PGA("Mic1 Amplifier", SUN6I_CODEC_MIC_CTRL,
1089 SUN6I_CODEC_MIC_CTRL_MIC1AMPEN, 0, NULL, 0),
1090 SND_SOC_DAPM_PGA("Mic2 Amplifier", SUN6I_CODEC_MIC_CTRL,
1091 SUN6I_CODEC_MIC_CTRL_MIC2AMPEN, 0, NULL, 0),
1092
Chen-Yu Tsaidff50512016-11-03 15:55:49 +08001093 /* Line In */
1094 SND_SOC_DAPM_INPUT("LINEIN"),
1095
Chen-Yu Tsai24c99f82016-11-07 18:06:59 +08001096 /* Digital parts of the ADCs */
1097 SND_SOC_DAPM_SUPPLY("ADC Enable", SUN6I_CODEC_ADC_FIFOC,
1098 SUN6I_CODEC_ADC_FIFOC_EN_AD, 0,
1099 NULL, 0),
1100
1101 /* Analog parts of the ADCs */
1102 SND_SOC_DAPM_ADC("Left ADC", "Codec Capture", SUN6I_CODEC_ADC_ACTL,
1103 SUN6I_CODEC_ADC_ACTL_ADCLEN, 0),
1104 SND_SOC_DAPM_ADC("Right ADC", "Codec Capture", SUN6I_CODEC_ADC_ACTL,
1105 SUN6I_CODEC_ADC_ACTL_ADCREN, 0),
1106
1107 /* ADC Mixers */
1108 SOC_MIXER_ARRAY("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
1109 sun6i_codec_adc_mixer_controls),
1110 SOC_MIXER_ARRAY("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
1111 sun6i_codec_adc_mixer_controls),
1112
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001113 /* Digital parts of the DACs */
1114 SND_SOC_DAPM_SUPPLY("DAC Enable", SUN4I_CODEC_DAC_DPC,
1115 SUN4I_CODEC_DAC_DPC_EN_DA, 0,
1116 NULL, 0),
1117
1118 /* Analog parts of the DACs */
1119 SND_SOC_DAPM_DAC("Left DAC", "Codec Playback",
1120 SUN6I_CODEC_OM_DACA_CTRL,
1121 SUN6I_CODEC_OM_DACA_CTRL_DACALEN, 0),
1122 SND_SOC_DAPM_DAC("Right DAC", "Codec Playback",
1123 SUN6I_CODEC_OM_DACA_CTRL,
1124 SUN6I_CODEC_OM_DACA_CTRL_DACAREN, 0),
1125
1126 /* Mixers */
1127 SOC_MIXER_ARRAY("Left Mixer", SUN6I_CODEC_OM_DACA_CTRL,
1128 SUN6I_CODEC_OM_DACA_CTRL_LMIXEN, 0,
1129 sun6i_codec_mixer_controls),
1130 SOC_MIXER_ARRAY("Right Mixer", SUN6I_CODEC_OM_DACA_CTRL,
1131 SUN6I_CODEC_OM_DACA_CTRL_RMIXEN, 0,
1132 sun6i_codec_mixer_controls),
1133
1134 /* Headphone output path */
1135 SND_SOC_DAPM_MUX("Headphone Source Playback Route",
1136 SND_SOC_NOPM, 0, 0, sun6i_codec_hp_src),
1137 SND_SOC_DAPM_OUT_DRV("Headphone Amp", SUN6I_CODEC_OM_PA_CTRL,
1138 SUN6I_CODEC_OM_PA_CTRL_HPPAEN, 0, NULL, 0),
1139 SND_SOC_DAPM_SUPPLY("HPCOM Protection", SUN6I_CODEC_OM_PA_CTRL,
1140 SUN6I_CODEC_OM_PA_CTRL_COMPTEN, 0, NULL, 0),
1141 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPCOM", SUN6I_CODEC_OM_PA_CTRL,
1142 SUN6I_CODEC_OM_PA_CTRL_HPCOM_CTL, 0x3, 0x3, 0),
1143 SND_SOC_DAPM_OUTPUT("HP"),
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001144
1145 /* Line Out path */
1146 SND_SOC_DAPM_MUX("Line Out Source Playback Route",
1147 SND_SOC_NOPM, 0, 0, sun6i_codec_lineout_src),
1148 SND_SOC_DAPM_OUTPUT("LINEOUT"),
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001149};
1150
1151static const struct snd_soc_dapm_route sun6i_codec_codec_dapm_routes[] = {
1152 /* DAC Routes */
1153 { "Left DAC", NULL, "DAC Enable" },
1154 { "Right DAC", NULL, "DAC Enable" },
1155
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001156 /* Microphone Routes */
1157 { "Mic1 Amplifier", NULL, "MIC1"},
1158 { "Mic2 Amplifier Source Route", "Mic2", "MIC2" },
1159 { "Mic2 Amplifier Source Route", "Mic3", "MIC3" },
1160 { "Mic2 Amplifier", NULL, "Mic2 Amplifier Source Route"},
1161
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001162 /* Left Mixer Routes */
1163 { "Left Mixer", "DAC Playback Switch", "Left DAC" },
1164 { "Left Mixer", "DAC Reversed Playback Switch", "Right DAC" },
Chen-Yu Tsaidff50512016-11-03 15:55:49 +08001165 { "Left Mixer", "Line In Playback Switch", "LINEIN" },
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001166 { "Left Mixer", "Mic1 Playback Switch", "Mic1 Amplifier" },
1167 { "Left Mixer", "Mic2 Playback Switch", "Mic2 Amplifier" },
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001168
1169 /* Right Mixer Routes */
1170 { "Right Mixer", "DAC Playback Switch", "Right DAC" },
1171 { "Right Mixer", "DAC Reversed Playback Switch", "Left DAC" },
Chen-Yu Tsaidff50512016-11-03 15:55:49 +08001172 { "Right Mixer", "Line In Playback Switch", "LINEIN" },
Chen-Yu Tsaiecd5cdb2016-11-03 15:55:51 +08001173 { "Right Mixer", "Mic1 Playback Switch", "Mic1 Amplifier" },
1174 { "Right Mixer", "Mic2 Playback Switch", "Mic2 Amplifier" },
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001175
Chen-Yu Tsai24c99f82016-11-07 18:06:59 +08001176 /* Left ADC Mixer Routes */
1177 { "Left ADC Mixer", "Mixer Capture Switch", "Left Mixer" },
1178 { "Left ADC Mixer", "Mixer Reversed Capture Switch", "Right Mixer" },
1179 { "Left ADC Mixer", "Line In Capture Switch", "LINEIN" },
1180 { "Left ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" },
1181 { "Left ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" },
1182
1183 /* Right ADC Mixer Routes */
1184 { "Right ADC Mixer", "Mixer Capture Switch", "Right Mixer" },
1185 { "Right ADC Mixer", "Mixer Reversed Capture Switch", "Left Mixer" },
1186 { "Right ADC Mixer", "Line In Capture Switch", "LINEIN" },
1187 { "Right ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" },
1188 { "Right ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" },
1189
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001190 /* Headphone Routes */
1191 { "Headphone Source Playback Route", "DAC", "Left DAC" },
1192 { "Headphone Source Playback Route", "DAC", "Right DAC" },
1193 { "Headphone Source Playback Route", "Mixer", "Left Mixer" },
1194 { "Headphone Source Playback Route", "Mixer", "Right Mixer" },
1195 { "Headphone Amp", NULL, "Headphone Source Playback Route" },
1196 { "HP", NULL, "Headphone Amp" },
1197 { "HPCOM", NULL, "HPCOM Protection" },
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001198
1199 /* Line Out Routes */
1200 { "Line Out Source Playback Route", "Stereo", "Left Mixer" },
1201 { "Line Out Source Playback Route", "Stereo", "Right Mixer" },
1202 { "Line Out Source Playback Route", "Mono Differential", "Left Mixer" },
Chen-Yu Tsai19426bd2017-01-08 02:57:06 +08001203 { "Line Out Source Playback Route", "Mono Differential", "Right Mixer" },
Chen-Yu Tsai0f909f92016-11-03 15:55:50 +08001204 { "LINEOUT", NULL, "Line Out Source Playback Route" },
Chen-Yu Tsai24c99f82016-11-07 18:06:59 +08001205
1206 /* ADC Routes */
1207 { "Left ADC", NULL, "ADC Enable" },
1208 { "Right ADC", NULL, "ADC Enable" },
1209 { "Left ADC", NULL, "Left ADC Mixer" },
1210 { "Right ADC", NULL, "Right ADC Mixer" },
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001211};
1212
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001213static const struct snd_soc_component_driver sun6i_codec_codec = {
1214 .controls = sun6i_codec_codec_widgets,
1215 .num_controls = ARRAY_SIZE(sun6i_codec_codec_widgets),
1216 .dapm_widgets = sun6i_codec_codec_dapm_widgets,
1217 .num_dapm_widgets = ARRAY_SIZE(sun6i_codec_codec_dapm_widgets),
1218 .dapm_routes = sun6i_codec_codec_dapm_routes,
1219 .num_dapm_routes = ARRAY_SIZE(sun6i_codec_codec_dapm_routes),
1220 .idle_bias_on = 1,
1221 .use_pmdown_time = 1,
1222 .endianness = 1,
1223 .non_legacy_dai_naming = 1,
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001224};
1225
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001226/* sun8i A23 codec */
1227static const struct snd_kcontrol_new sun8i_a23_codec_codec_controls[] = {
1228 SOC_SINGLE_TLV("DAC Playback Volume", SUN4I_CODEC_DAC_DPC,
1229 SUN4I_CODEC_DAC_DPC_DVOL, 0x3f, 1,
1230 sun6i_codec_dvol_scale),
1231};
1232
1233static const struct snd_soc_dapm_widget sun8i_a23_codec_codec_widgets[] = {
1234 /* Digital parts of the ADCs */
1235 SND_SOC_DAPM_SUPPLY("ADC Enable", SUN6I_CODEC_ADC_FIFOC,
1236 SUN6I_CODEC_ADC_FIFOC_EN_AD, 0, NULL, 0),
1237 /* Digital parts of the DACs */
1238 SND_SOC_DAPM_SUPPLY("DAC Enable", SUN4I_CODEC_DAC_DPC,
1239 SUN4I_CODEC_DAC_DPC_EN_DA, 0, NULL, 0),
1240
1241};
1242
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001243static const struct snd_soc_component_driver sun8i_a23_codec_codec = {
1244 .controls = sun8i_a23_codec_codec_controls,
1245 .num_controls = ARRAY_SIZE(sun8i_a23_codec_codec_controls),
1246 .dapm_widgets = sun8i_a23_codec_codec_widgets,
1247 .num_dapm_widgets = ARRAY_SIZE(sun8i_a23_codec_codec_widgets),
1248 .idle_bias_on = 1,
1249 .use_pmdown_time = 1,
1250 .endianness = 1,
1251 .non_legacy_dai_naming = 1,
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001252};
1253
Emilio López45fb6b62015-09-12 15:26:24 +02001254static const struct snd_soc_component_driver sun4i_codec_component = {
1255 .name = "sun4i-codec",
1256};
1257
Andrea Bondavalli5a0cf022017-12-12 10:14:50 +01001258#define SUN4I_CODEC_RATES SNDRV_PCM_RATE_CONTINUOUS
Emilio López45fb6b62015-09-12 15:26:24 +02001259#define SUN4I_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
1260 SNDRV_PCM_FMTBIT_S32_LE)
1261
1262static int sun4i_codec_dai_probe(struct snd_soc_dai *dai)
1263{
1264 struct snd_soc_card *card = snd_soc_dai_get_drvdata(dai);
1265 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card);
1266
1267 snd_soc_dai_init_dma_data(dai, &scodec->playback_dma_data,
Maxime Ripard1fb34b42015-11-30 16:37:47 +01001268 &scodec->capture_dma_data);
Emilio López45fb6b62015-09-12 15:26:24 +02001269
1270 return 0;
1271}
1272
1273static struct snd_soc_dai_driver dummy_cpu_dai = {
1274 .name = "sun4i-codec-cpu-dai",
1275 .probe = sun4i_codec_dai_probe,
1276 .playback = {
1277 .stream_name = "Playback",
1278 .channels_min = 1,
1279 .channels_max = 2,
1280 .rates = SUN4I_CODEC_RATES,
1281 .formats = SUN4I_CODEC_FORMATS,
1282 .sig_bits = 24,
1283 },
Maxime Ripard1fb34b42015-11-30 16:37:47 +01001284 .capture = {
1285 .stream_name = "Capture",
1286 .channels_min = 1,
1287 .channels_max = 2,
1288 .rates = SUN4I_CODEC_RATES,
1289 .formats = SUN4I_CODEC_FORMATS,
1290 .sig_bits = 24,
1291 },
Emilio López45fb6b62015-09-12 15:26:24 +02001292};
1293
Emilio López45fb6b62015-09-12 15:26:24 +02001294static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev,
1295 int *num_links)
1296{
1297 struct snd_soc_dai_link *link = devm_kzalloc(dev, sizeof(*link),
1298 GFP_KERNEL);
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001299 struct snd_soc_dai_link_component *dlc = devm_kzalloc(dev,
Kuninori Morimotod3569a42019-06-28 10:48:35 +09001300 3 * sizeof(*dlc), GFP_KERNEL);
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001301 if (!link || !dlc)
Emilio López45fb6b62015-09-12 15:26:24 +02001302 return NULL;
1303
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001304 link->cpus = &dlc[0];
1305 link->codecs = &dlc[1];
Kuninori Morimotod3569a42019-06-28 10:48:35 +09001306 link->platforms = &dlc[2];
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001307
1308 link->num_cpus = 1;
1309 link->num_codecs = 1;
Kuninori Morimotod3569a42019-06-28 10:48:35 +09001310 link->num_platforms = 1;
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001311
Emilio López45fb6b62015-09-12 15:26:24 +02001312 link->name = "cdc";
1313 link->stream_name = "CDC PCM";
Kuninori Morimoto950d10e2019-06-06 13:18:19 +09001314 link->codecs->dai_name = "Codec";
1315 link->cpus->dai_name = dev_name(dev);
1316 link->codecs->name = dev_name(dev);
Kuninori Morimotod3569a42019-06-28 10:48:35 +09001317 link->platforms->name = dev_name(dev);
Emilio López45fb6b62015-09-12 15:26:24 +02001318 link->dai_fmt = SND_SOC_DAIFMT_I2S;
1319
1320 *num_links = 1;
1321
1322 return link;
1323};
1324
Hans de Goede40592622015-12-11 19:43:57 +01001325static int sun4i_codec_spk_event(struct snd_soc_dapm_widget *w,
1326 struct snd_kcontrol *k, int event)
1327{
1328 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(w->dapm->card);
1329
Fabio Estevamd51579e2017-07-16 18:11:06 -03001330 gpiod_set_value_cansleep(scodec->gpio_pa,
1331 !!SND_SOC_DAPM_EVENT_ON(event));
Hans de Goede40592622015-12-11 19:43:57 +01001332
Georgii Staroselskii1f2675f2019-05-28 13:47:39 +03001333 if (SND_SOC_DAPM_EVENT_ON(event)) {
1334 /*
1335 * Need a delay to wait for DAC to push the data. 700ms seems
1336 * to be the best compromise not to feel this delay while
1337 * playing a sound.
1338 */
1339 msleep(700);
1340 }
1341
Hans de Goede40592622015-12-11 19:43:57 +01001342 return 0;
1343}
1344
1345static const struct snd_soc_dapm_widget sun4i_codec_card_dapm_widgets[] = {
1346 SND_SOC_DAPM_SPK("Speaker", sun4i_codec_spk_event),
1347};
1348
1349static const struct snd_soc_dapm_route sun4i_codec_card_dapm_routes[] = {
Hans de Goede6b803c62015-12-22 23:00:17 +01001350 { "Speaker", NULL, "HP Right" },
1351 { "Speaker", NULL, "HP Left" },
Hans de Goede40592622015-12-11 19:43:57 +01001352};
1353
Emilio López45fb6b62015-09-12 15:26:24 +02001354static struct snd_soc_card *sun4i_codec_create_card(struct device *dev)
1355{
1356 struct snd_soc_card *card;
Emilio López45fb6b62015-09-12 15:26:24 +02001357
1358 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1359 if (!card)
Chen-Yu Tsai85915b62016-10-31 14:42:09 +08001360 return ERR_PTR(-ENOMEM);
Emilio López45fb6b62015-09-12 15:26:24 +02001361
1362 card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1363 if (!card->dai_link)
Chen-Yu Tsai85915b62016-10-31 14:42:09 +08001364 return ERR_PTR(-ENOMEM);
Emilio López45fb6b62015-09-12 15:26:24 +02001365
1366 card->dev = dev;
Bastian Germann7c0d6e42021-03-31 17:18:43 +02001367 card->owner = THIS_MODULE;
Emilio López45fb6b62015-09-12 15:26:24 +02001368 card->name = "sun4i-codec";
Hans de Goede40592622015-12-11 19:43:57 +01001369 card->dapm_widgets = sun4i_codec_card_dapm_widgets;
1370 card->num_dapm_widgets = ARRAY_SIZE(sun4i_codec_card_dapm_widgets);
1371 card->dapm_routes = sun4i_codec_card_dapm_routes;
1372 card->num_dapm_routes = ARRAY_SIZE(sun4i_codec_card_dapm_routes);
Emilio López45fb6b62015-09-12 15:26:24 +02001373
Emilio López45fb6b62015-09-12 15:26:24 +02001374 return card;
1375};
1376
Chen-Yu Tsai300a18d2016-11-03 15:55:53 +08001377static const struct snd_soc_dapm_widget sun6i_codec_card_dapm_widgets[] = {
1378 SND_SOC_DAPM_HP("Headphone", NULL),
1379 SND_SOC_DAPM_LINE("Line In", NULL),
1380 SND_SOC_DAPM_LINE("Line Out", NULL),
1381 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1382 SND_SOC_DAPM_MIC("Mic", NULL),
1383 SND_SOC_DAPM_SPK("Speaker", sun4i_codec_spk_event),
1384};
1385
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001386static struct snd_soc_card *sun6i_codec_create_card(struct device *dev)
1387{
1388 struct snd_soc_card *card;
Chen-Yu Tsai300a18d2016-11-03 15:55:53 +08001389 int ret;
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001390
1391 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1392 if (!card)
1393 return ERR_PTR(-ENOMEM);
1394
1395 card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1396 if (!card->dai_link)
1397 return ERR_PTR(-ENOMEM);
1398
Chen-Yu Tsai300a18d2016-11-03 15:55:53 +08001399 card->dev = dev;
Bastian Germann7c0d6e42021-03-31 17:18:43 +02001400 card->owner = THIS_MODULE;
Chen-Yu Tsai300a18d2016-11-03 15:55:53 +08001401 card->name = "A31 Audio Codec";
1402 card->dapm_widgets = sun6i_codec_card_dapm_widgets;
1403 card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets);
1404 card->fully_routed = true;
1405
1406 ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing");
1407 if (ret)
1408 dev_warn(dev, "failed to parse audio-routing: %d\n", ret);
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001409
1410 return card;
1411};
1412
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001413/* Connect digital side enables to analog side widgets */
1414static const struct snd_soc_dapm_route sun8i_codec_card_routes[] = {
1415 /* ADC Routes */
1416 { "Left ADC", NULL, "ADC Enable" },
1417 { "Right ADC", NULL, "ADC Enable" },
1418 { "Codec Capture", NULL, "Left ADC" },
1419 { "Codec Capture", NULL, "Right ADC" },
1420
1421 /* DAC Routes */
1422 { "Left DAC", NULL, "DAC Enable" },
1423 { "Right DAC", NULL, "DAC Enable" },
1424 { "Left DAC", NULL, "Codec Playback" },
1425 { "Right DAC", NULL, "Codec Playback" },
1426};
1427
1428static struct snd_soc_aux_dev aux_dev = {
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001429 .dlc = COMP_EMPTY(),
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001430};
1431
1432static struct snd_soc_card *sun8i_a23_codec_create_card(struct device *dev)
1433{
1434 struct snd_soc_card *card;
1435 int ret;
1436
1437 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1438 if (!card)
1439 return ERR_PTR(-ENOMEM);
1440
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001441 aux_dev.dlc.of_node = of_parse_phandle(dev->of_node,
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001442 "allwinner,codec-analog-controls",
1443 0);
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001444 if (!aux_dev.dlc.of_node) {
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001445 dev_err(dev, "Can't find analog controls for codec.\n");
1446 return ERR_PTR(-EINVAL);
YueHaibing24d05962019-10-25 20:08:01 +08001447 }
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001448
1449 card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1450 if (!card->dai_link)
1451 return ERR_PTR(-ENOMEM);
1452
1453 card->dev = dev;
Bastian Germann7c0d6e42021-03-31 17:18:43 +02001454 card->owner = THIS_MODULE;
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001455 card->name = "A23 Audio Codec";
1456 card->dapm_widgets = sun6i_codec_card_dapm_widgets;
1457 card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets);
1458 card->dapm_routes = sun8i_codec_card_routes;
1459 card->num_dapm_routes = ARRAY_SIZE(sun8i_codec_card_routes);
1460 card->aux_dev = &aux_dev;
1461 card->num_aux_devs = 1;
1462 card->fully_routed = true;
1463
1464 ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing");
1465 if (ret)
1466 dev_warn(dev, "failed to parse audio-routing: %d\n", ret);
1467
1468 return card;
1469};
1470
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001471static struct snd_soc_card *sun8i_h3_codec_create_card(struct device *dev)
1472{
1473 struct snd_soc_card *card;
1474 int ret;
1475
1476 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1477 if (!card)
1478 return ERR_PTR(-ENOMEM);
1479
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001480 aux_dev.dlc.of_node = of_parse_phandle(dev->of_node,
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001481 "allwinner,codec-analog-controls",
1482 0);
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001483 if (!aux_dev.dlc.of_node) {
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001484 dev_err(dev, "Can't find analog controls for codec.\n");
1485 return ERR_PTR(-EINVAL);
YueHaibing24d05962019-10-25 20:08:01 +08001486 }
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001487
1488 card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1489 if (!card->dai_link)
1490 return ERR_PTR(-ENOMEM);
1491
1492 card->dev = dev;
Bastian Germann7c0d6e42021-03-31 17:18:43 +02001493 card->owner = THIS_MODULE;
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001494 card->name = "H3 Audio Codec";
1495 card->dapm_widgets = sun6i_codec_card_dapm_widgets;
1496 card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets);
1497 card->dapm_routes = sun8i_codec_card_routes;
1498 card->num_dapm_routes = ARRAY_SIZE(sun8i_codec_card_routes);
1499 card->aux_dev = &aux_dev;
1500 card->num_aux_devs = 1;
1501 card->fully_routed = true;
1502
1503 ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing");
1504 if (ret)
1505 dev_warn(dev, "failed to parse audio-routing: %d\n", ret);
1506
1507 return card;
1508};
1509
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001510static struct snd_soc_card *sun8i_v3s_codec_create_card(struct device *dev)
1511{
1512 struct snd_soc_card *card;
1513 int ret;
1514
1515 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1516 if (!card)
1517 return ERR_PTR(-ENOMEM);
1518
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001519 aux_dev.dlc.of_node = of_parse_phandle(dev->of_node,
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001520 "allwinner,codec-analog-controls",
1521 0);
Kuninori Morimoto3d0d2d62019-08-08 14:54:25 +09001522 if (!aux_dev.dlc.of_node) {
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001523 dev_err(dev, "Can't find analog controls for codec.\n");
1524 return ERR_PTR(-EINVAL);
YueHaibing24d05962019-10-25 20:08:01 +08001525 }
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001526
1527 card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1528 if (!card->dai_link)
1529 return ERR_PTR(-ENOMEM);
1530
1531 card->dev = dev;
Bastian Germann7c0d6e42021-03-31 17:18:43 +02001532 card->owner = THIS_MODULE;
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001533 card->name = "V3s Audio Codec";
1534 card->dapm_widgets = sun6i_codec_card_dapm_widgets;
1535 card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets);
1536 card->dapm_routes = sun8i_codec_card_routes;
1537 card->num_dapm_routes = ARRAY_SIZE(sun8i_codec_card_routes);
1538 card->aux_dev = &aux_dev;
1539 card->num_aux_devs = 1;
1540 card->fully_routed = true;
1541
1542 ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing");
1543 if (ret)
1544 dev_warn(dev, "failed to parse audio-routing: %d\n", ret);
1545
1546 return card;
1547};
1548
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001549static const struct regmap_config sun4i_codec_regmap_config = {
1550 .reg_bits = 32,
1551 .reg_stride = 4,
1552 .val_bits = 32,
1553 .max_register = SUN4I_CODEC_ADC_RXCNT,
1554};
1555
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001556static const struct regmap_config sun6i_codec_regmap_config = {
1557 .reg_bits = 32,
1558 .reg_stride = 4,
1559 .val_bits = 32,
1560 .max_register = SUN6I_CODEC_HMIC_DATA,
1561};
1562
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001563static const struct regmap_config sun7i_codec_regmap_config = {
1564 .reg_bits = 32,
1565 .reg_stride = 4,
1566 .val_bits = 32,
1567 .max_register = SUN7I_CODEC_AC_MIC_PHONE_CAL,
1568};
1569
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001570static const struct regmap_config sun8i_a23_codec_regmap_config = {
1571 .reg_bits = 32,
1572 .reg_stride = 4,
1573 .val_bits = 32,
1574 .max_register = SUN8I_A23_CODEC_ADC_RXCNT,
1575};
1576
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001577static const struct regmap_config sun8i_h3_codec_regmap_config = {
1578 .reg_bits = 32,
1579 .reg_stride = 4,
1580 .val_bits = 32,
1581 .max_register = SUN8I_H3_CODEC_ADC_DBG,
1582};
1583
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001584static const struct regmap_config sun8i_v3s_codec_regmap_config = {
1585 .reg_bits = 32,
1586 .reg_stride = 4,
1587 .val_bits = 32,
1588 .max_register = SUN8I_H3_CODEC_ADC_DBG,
1589};
1590
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001591struct sun4i_codec_quirks {
1592 const struct regmap_config *regmap_config;
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001593 const struct snd_soc_component_driver *codec;
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001594 struct snd_soc_card * (*create_card)(struct device *dev);
1595 struct reg_field reg_adc_fifoc; /* used for regmap_field */
1596 unsigned int reg_dac_txdata; /* TX FIFO offset for DMA config */
1597 unsigned int reg_adc_rxdata; /* RX FIFO offset for DMA config */
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001598 bool has_reset;
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001599};
1600
1601static const struct sun4i_codec_quirks sun4i_codec_quirks = {
1602 .regmap_config = &sun4i_codec_regmap_config,
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001603 .codec = &sun4i_codec_codec,
1604 .create_card = sun4i_codec_create_card,
1605 .reg_adc_fifoc = REG_FIELD(SUN4I_CODEC_ADC_FIFOC, 0, 31),
1606 .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA,
1607 .reg_adc_rxdata = SUN4I_CODEC_ADC_RXDATA,
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001608};
1609
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001610static const struct sun4i_codec_quirks sun6i_a31_codec_quirks = {
1611 .regmap_config = &sun6i_codec_regmap_config,
1612 .codec = &sun6i_codec_codec,
1613 .create_card = sun6i_codec_create_card,
1614 .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31),
1615 .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA,
1616 .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA,
1617 .has_reset = true,
1618};
1619
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001620static const struct sun4i_codec_quirks sun7i_codec_quirks = {
1621 .regmap_config = &sun7i_codec_regmap_config,
Danny Milosavljevicb71a7eb2019-01-30 11:39:39 +01001622 .codec = &sun7i_codec_codec,
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001623 .create_card = sun4i_codec_create_card,
1624 .reg_adc_fifoc = REG_FIELD(SUN4I_CODEC_ADC_FIFOC, 0, 31),
1625 .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA,
1626 .reg_adc_rxdata = SUN4I_CODEC_ADC_RXDATA,
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001627};
1628
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001629static const struct sun4i_codec_quirks sun8i_a23_codec_quirks = {
1630 .regmap_config = &sun8i_a23_codec_regmap_config,
1631 .codec = &sun8i_a23_codec_codec,
1632 .create_card = sun8i_a23_codec_create_card,
1633 .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31),
1634 .reg_dac_txdata = SUN4I_CODEC_DAC_TXDATA,
1635 .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA,
1636 .has_reset = true,
1637};
1638
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001639static const struct sun4i_codec_quirks sun8i_h3_codec_quirks = {
1640 .regmap_config = &sun8i_h3_codec_regmap_config,
1641 /*
1642 * TODO Share the codec structure with A23 for now.
1643 * This should be split out when adding digital audio
1644 * processing support for the H3.
1645 */
1646 .codec = &sun8i_a23_codec_codec,
1647 .create_card = sun8i_h3_codec_create_card,
1648 .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31),
1649 .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA,
1650 .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA,
1651 .has_reset = true,
1652};
1653
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001654static const struct sun4i_codec_quirks sun8i_v3s_codec_quirks = {
1655 .regmap_config = &sun8i_v3s_codec_regmap_config,
1656 /*
1657 * TODO The codec structure should be split out, like
1658 * H3, when adding digital audio processing support.
1659 */
1660 .codec = &sun8i_a23_codec_codec,
1661 .create_card = sun8i_v3s_codec_create_card,
1662 .reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31),
1663 .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA,
1664 .reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA,
1665 .has_reset = true,
1666};
1667
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001668static const struct of_device_id sun4i_codec_of_match[] = {
1669 {
1670 .compatible = "allwinner,sun4i-a10-codec",
1671 .data = &sun4i_codec_quirks,
1672 },
1673 {
Chen-Yu Tsai8d9e4c9e2016-11-03 15:55:48 +08001674 .compatible = "allwinner,sun6i-a31-codec",
1675 .data = &sun6i_a31_codec_quirks,
1676 },
1677 {
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001678 .compatible = "allwinner,sun7i-a20-codec",
1679 .data = &sun7i_codec_quirks,
1680 },
Chen-Yu Tsaidac5f862016-11-25 20:34:36 +08001681 {
1682 .compatible = "allwinner,sun8i-a23-codec",
1683 .data = &sun8i_a23_codec_quirks,
1684 },
Chen-Yu Tsai4a15b242016-11-25 20:34:40 +08001685 {
1686 .compatible = "allwinner,sun8i-h3-codec",
1687 .data = &sun8i_h3_codec_quirks,
1688 },
Icenowy Zheng8b2840b2017-06-05 21:27:22 +08001689 {
1690 .compatible = "allwinner,sun8i-v3s-codec",
1691 .data = &sun8i_v3s_codec_quirks,
1692 },
Chen-Yu Tsai2f2a3462016-11-03 15:55:43 +08001693 {}
1694};
1695MODULE_DEVICE_TABLE(of, sun4i_codec_of_match);
1696
Emilio López45fb6b62015-09-12 15:26:24 +02001697static int sun4i_codec_probe(struct platform_device *pdev)
1698{
1699 struct snd_soc_card *card;
1700 struct sun4i_codec *scodec;
Danny Milosavljevicc1d50652016-09-22 09:13:13 +02001701 const struct sun4i_codec_quirks *quirks;
Emilio López45fb6b62015-09-12 15:26:24 +02001702 struct resource *res;
1703 void __iomem *base;
1704 int ret;
1705
1706 scodec = devm_kzalloc(&pdev->dev, sizeof(*scodec), GFP_KERNEL);
1707 if (!scodec)
1708 return -ENOMEM;
1709
1710 scodec->dev = &pdev->dev;
1711
Yang Yingliang37c617f2021-06-17 12:50:10 +08001712 base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
Muhammad Usama Anjuma93799d2021-04-07 14:56:34 +05001713 if (IS_ERR(base))
Emilio López45fb6b62015-09-12 15:26:24 +02001714 return PTR_ERR(base);
Emilio López45fb6b62015-09-12 15:26:24 +02001715
Danny Milosavljevicc1d50652016-09-22 09:13:13 +02001716 quirks = of_device_get_match_data(&pdev->dev);
1717 if (quirks == NULL) {
1718 dev_err(&pdev->dev, "Failed to determine the quirks to use\n");
1719 return -ENODEV;
1720 }
1721
Emilio López45fb6b62015-09-12 15:26:24 +02001722 scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base,
Danny Milosavljevicc1d50652016-09-22 09:13:13 +02001723 quirks->regmap_config);
Emilio López45fb6b62015-09-12 15:26:24 +02001724 if (IS_ERR(scodec->regmap)) {
1725 dev_err(&pdev->dev, "Failed to create our regmap\n");
1726 return PTR_ERR(scodec->regmap);
1727 }
1728
1729 /* Get the clocks from the DT */
1730 scodec->clk_apb = devm_clk_get(&pdev->dev, "apb");
1731 if (IS_ERR(scodec->clk_apb)) {
1732 dev_err(&pdev->dev, "Failed to get the APB clock\n");
1733 return PTR_ERR(scodec->clk_apb);
1734 }
1735
1736 scodec->clk_module = devm_clk_get(&pdev->dev, "codec");
1737 if (IS_ERR(scodec->clk_module)) {
1738 dev_err(&pdev->dev, "Failed to get the module clock\n");
1739 return PTR_ERR(scodec->clk_module);
1740 }
1741
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001742 if (quirks->has_reset) {
Philipp Zabel72bfa212017-07-19 17:26:43 +02001743 scodec->rst = devm_reset_control_get_exclusive(&pdev->dev,
1744 NULL);
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001745 if (IS_ERR(scodec->rst)) {
1746 dev_err(&pdev->dev, "Failed to get reset control\n");
1747 return PTR_ERR(scodec->rst);
1748 }
kbuild test robot35db5762016-11-10 00:35:18 +08001749 }
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001750
Hans de Goede40592622015-12-11 19:43:57 +01001751 scodec->gpio_pa = devm_gpiod_get_optional(&pdev->dev, "allwinner,pa",
1752 GPIOD_OUT_LOW);
1753 if (IS_ERR(scodec->gpio_pa)) {
1754 ret = PTR_ERR(scodec->gpio_pa);
1755 if (ret != -EPROBE_DEFER)
1756 dev_err(&pdev->dev, "Failed to get pa gpio: %d\n", ret);
1757 return ret;
1758 }
1759
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001760 /* reg_field setup */
1761 scodec->reg_adc_fifoc = devm_regmap_field_alloc(&pdev->dev,
1762 scodec->regmap,
1763 quirks->reg_adc_fifoc);
1764 if (IS_ERR(scodec->reg_adc_fifoc)) {
1765 ret = PTR_ERR(scodec->reg_adc_fifoc);
1766 dev_err(&pdev->dev, "Failed to create regmap fields: %d\n",
1767 ret);
1768 return ret;
1769 }
1770
Chen-Yu Tsai3716a892016-11-01 14:31:55 +08001771 /* Enable the bus clock */
1772 if (clk_prepare_enable(scodec->clk_apb)) {
1773 dev_err(&pdev->dev, "Failed to enable the APB clock\n");
1774 return -EINVAL;
1775 }
1776
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001777 /* Deassert the reset control */
1778 if (scodec->rst) {
1779 ret = reset_control_deassert(scodec->rst);
1780 if (ret) {
1781 dev_err(&pdev->dev,
1782 "Failed to deassert the reset control\n");
1783 goto err_clk_disable;
1784 }
1785 }
1786
Emilio López45fb6b62015-09-12 15:26:24 +02001787 /* DMA configuration for TX FIFO */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001788 scodec->playback_dma_data.addr = res->start + quirks->reg_dac_txdata;
Chen-Yu Tsai730e2dd2016-11-03 15:55:46 +08001789 scodec->playback_dma_data.maxburst = 8;
Emilio López45fb6b62015-09-12 15:26:24 +02001790 scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
1791
Maxime Ripard1fb34b42015-11-30 16:37:47 +01001792 /* DMA configuration for RX FIFO */
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001793 scodec->capture_dma_data.addr = res->start + quirks->reg_adc_rxdata;
Chen-Yu Tsai730e2dd2016-11-03 15:55:46 +08001794 scodec->capture_dma_data.maxburst = 8;
Maxime Ripard1fb34b42015-11-30 16:37:47 +01001795 scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
1796
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001797 ret = devm_snd_soc_register_component(&pdev->dev, quirks->codec,
Emilio López45fb6b62015-09-12 15:26:24 +02001798 &sun4i_codec_dai, 1);
1799 if (ret) {
1800 dev_err(&pdev->dev, "Failed to register our codec\n");
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001801 goto err_assert_reset;
Emilio López45fb6b62015-09-12 15:26:24 +02001802 }
1803
1804 ret = devm_snd_soc_register_component(&pdev->dev,
1805 &sun4i_codec_component,
1806 &dummy_cpu_dai, 1);
1807 if (ret) {
1808 dev_err(&pdev->dev, "Failed to register our DAI\n");
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001809 goto err_assert_reset;
Emilio López45fb6b62015-09-12 15:26:24 +02001810 }
1811
1812 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
1813 if (ret) {
1814 dev_err(&pdev->dev, "Failed to register against DMAEngine\n");
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001815 goto err_assert_reset;
Emilio López45fb6b62015-09-12 15:26:24 +02001816 }
1817
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001818 card = quirks->create_card(&pdev->dev);
Chen-Yu Tsai85915b62016-10-31 14:42:09 +08001819 if (IS_ERR(card)) {
1820 ret = PTR_ERR(card);
Emilio López45fb6b62015-09-12 15:26:24 +02001821 dev_err(&pdev->dev, "Failed to create our card\n");
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001822 goto err_assert_reset;
Emilio López45fb6b62015-09-12 15:26:24 +02001823 }
1824
Emilio López45fb6b62015-09-12 15:26:24 +02001825 snd_soc_card_set_drvdata(card, scodec);
1826
1827 ret = snd_soc_register_card(card);
1828 if (ret) {
1829 dev_err(&pdev->dev, "Failed to register our card\n");
Kuninori Morimoto77f4be162018-01-29 04:23:46 +00001830 goto err_assert_reset;
Emilio López45fb6b62015-09-12 15:26:24 +02001831 }
1832
1833 return 0;
1834
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001835err_assert_reset:
1836 if (scodec->rst)
1837 reset_control_assert(scodec->rst);
Emilio López45fb6b62015-09-12 15:26:24 +02001838err_clk_disable:
1839 clk_disable_unprepare(scodec->clk_apb);
1840 return ret;
1841}
1842
1843static int sun4i_codec_remove(struct platform_device *pdev)
1844{
1845 struct snd_soc_card *card = platform_get_drvdata(pdev);
1846 struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card);
1847
1848 snd_soc_unregister_card(card);
Chen-Yu Tsai9aead152016-11-07 18:06:58 +08001849 if (scodec->rst)
1850 reset_control_assert(scodec->rst);
Emilio López45fb6b62015-09-12 15:26:24 +02001851 clk_disable_unprepare(scodec->clk_apb);
1852
1853 return 0;
1854}
1855
1856static struct platform_driver sun4i_codec_driver = {
1857 .driver = {
1858 .name = "sun4i-codec",
Emilio López45fb6b62015-09-12 15:26:24 +02001859 .of_match_table = sun4i_codec_of_match,
1860 },
1861 .probe = sun4i_codec_probe,
1862 .remove = sun4i_codec_remove,
1863};
1864module_platform_driver(sun4i_codec_driver);
1865
1866MODULE_DESCRIPTION("Allwinner A10 codec driver");
1867MODULE_AUTHOR("Emilio López <emilio@elopez.com.ar>");
1868MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
1869MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
Chen-Yu Tsaibc03f0d2016-11-03 15:55:44 +08001870MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
Emilio López45fb6b62015-09-12 15:26:24 +02001871MODULE_LICENSE("GPL");