brcm2708: add linux 4.1 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0048-Added-driver-for-HiFiBerry-Amp-amplifier-add-on-boar.patch
1 From ee406533a463686db7d11c7ad0f626578c1edcac Mon Sep 17 00:00:00 2001
2 From: Daniel Matuschek <info@crazy-audio.com>
3 Date: Mon, 4 Aug 2014 11:09:58 +0200
4 Subject: [PATCH 048/121] Added driver for HiFiBerry Amp amplifier add-on board
5
6 The driver contains a low-level hardware driver for the TAS5713 and the
7 drivers for the Raspberry Pi I2S subsystem.
8
9 TAS5713: return error if initialisation fails
10
11 Existing TAS5713 driver logs errors during initialisation, but does not return
12 an error code. Therefore even if initialisation fails, the driver will still be
13 loaded, but won't work. This patch fixes this. I2C communication error will now
14 reported correctly by a non-zero return code.
15
16 HiFiBerry Amp: fix device-tree problems
17
18 Some code to load the driver based on device-tree-overlays was missing. This is added by this patch.
19 ---
20 arch/arm/mach-bcm2708/bcm2708.c | 19 +++
21 sound/soc/bcm/Kconfig | 7 +
22 sound/soc/bcm/Makefile | 2 +
23 sound/soc/bcm/hifiberry_amp.c | 127 ++++++++++++++
24 sound/soc/codecs/Kconfig | 4 +
25 sound/soc/codecs/Makefile | 2 +
26 sound/soc/codecs/tas5713.c | 369 ++++++++++++++++++++++++++++++++++++++++
27 sound/soc/codecs/tas5713.h | 210 +++++++++++++++++++++++
28 8 files changed, 740 insertions(+)
29 create mode 100644 sound/soc/bcm/hifiberry_amp.c
30 create mode 100644 sound/soc/codecs/tas5713.c
31 create mode 100644 sound/soc/codecs/tas5713.h
32
33 --- a/arch/arm/mach-bcm2708/bcm2708.c
34 +++ b/arch/arm/mach-bcm2708/bcm2708.c
35 @@ -681,6 +681,20 @@ static struct i2c_board_info __initdata
36
37 #endif
38
39 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
40 +static struct platform_device snd_hifiberry_amp_device = {
41 + .name = "snd-hifiberry-amp",
42 + .id = 0,
43 + .num_resources = 0,
44 +};
45 +
46 +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
47 + {
48 + I2C_BOARD_INFO("tas5713", 0x1b)
49 + },
50 +};
51 +#endif
52 +
53 #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
54 static struct platform_device snd_rpi_dac_device = {
55 .name = "snd-rpi-dac",
56 @@ -894,6 +908,11 @@ void __init bcm2708_init(void)
57 i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
58 #endif
59
60 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
61 + bcm_register_device_dt(&snd_hifiberry_amp_device);
62 + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
63 +#endif
64 +
65 #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
66 bcm_register_device_dt(&snd_rpi_dac_device);
67 bcm_register_device_dt(&snd_pcm1794a_codec_device);
68 --- a/sound/soc/bcm/Kconfig
69 +++ b/sound/soc/bcm/Kconfig
70 @@ -40,6 +40,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DIGI
71 help
72 Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
73
74 +config SND_BCM2708_SOC_HIFIBERRY_AMP
75 + tristate "Support for the HifiBerry Amp"
76 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
77 + select SND_SOC_TAS5713
78 + help
79 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
80 +
81 config SND_BCM2708_SOC_RPI_DAC
82 tristate "Support for RPi-DAC"
83 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
84 --- a/sound/soc/bcm/Makefile
85 +++ b/sound/soc/bcm/Makefile
86 @@ -12,11 +12,13 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
87 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
88 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
89 snd-soc-hifiberry-digi-objs := hifiberry_digi.o
90 +snd-soc-hifiberry-amp-objs := hifiberry_amp.o
91 snd-soc-rpi-dac-objs := rpi-dac.o
92 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
93
94 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
95 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
96 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
97 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
98 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
99 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
100 --- /dev/null
101 +++ b/sound/soc/bcm/hifiberry_amp.c
102 @@ -0,0 +1,127 @@
103 +/*
104 + * ASoC Driver for HifiBerry AMP
105 + *
106 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
107 + * Copyright 2014
108 + *
109 + * This program is free software; you can redistribute it and/or
110 + * modify it under the terms of the GNU General Public License
111 + * version 2 as published by the Free Software Foundation.
112 + *
113 + * This program is distributed in the hope that it will be useful, but
114 + * WITHOUT ANY WARRANTY; without even the implied warranty of
115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
116 + * General Public License for more details.
117 + */
118 +
119 +#include <linux/module.h>
120 +#include <linux/platform_device.h>
121 +
122 +#include <sound/core.h>
123 +#include <sound/pcm.h>
124 +#include <sound/pcm_params.h>
125 +#include <sound/soc.h>
126 +#include <sound/jack.h>
127 +
128 +static int snd_rpi_hifiberry_amp_init(struct snd_soc_pcm_runtime *rtd)
129 +{
130 + // ToDo: init of the dsp-registers.
131 + return 0;
132 +}
133 +
134 +static int snd_rpi_hifiberry_amp_hw_params( struct snd_pcm_substream *substream,
135 + struct snd_pcm_hw_params *params )
136 +{
137 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
138 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
139 +
140 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
141 +}
142 +
143 +static struct snd_soc_ops snd_rpi_hifiberry_amp_ops = {
144 + .hw_params = snd_rpi_hifiberry_amp_hw_params,
145 +};
146 +
147 +static struct snd_soc_dai_link snd_rpi_hifiberry_amp_dai[] = {
148 + {
149 + .name = "HifiBerry AMP",
150 + .stream_name = "HifiBerry AMP HiFi",
151 + .cpu_dai_name = "bcm2708-i2s.0",
152 + .codec_dai_name = "tas5713-hifi",
153 + .platform_name = "bcm2708-i2s.0",
154 + .codec_name = "tas5713.1-001b",
155 + .dai_fmt = SND_SOC_DAIFMT_I2S |
156 + SND_SOC_DAIFMT_NB_NF |
157 + SND_SOC_DAIFMT_CBS_CFS,
158 + .ops = &snd_rpi_hifiberry_amp_ops,
159 + .init = snd_rpi_hifiberry_amp_init,
160 + },
161 +};
162 +
163 +
164 +static struct snd_soc_card snd_rpi_hifiberry_amp = {
165 + .name = "snd_rpi_hifiberry_amp",
166 + .dai_link = snd_rpi_hifiberry_amp_dai,
167 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_amp_dai),
168 +};
169 +
170 +static const struct of_device_id snd_rpi_hifiberry_amp_of_match[] = {
171 + { .compatible = "hifiberry,hifiberry-amp", },
172 + {},
173 +};
174 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_amp_of_match);
175 +
176 +
177 +static int snd_rpi_hifiberry_amp_probe(struct platform_device *pdev)
178 +{
179 + int ret = 0;
180 +
181 + snd_rpi_hifiberry_amp.dev = &pdev->dev;
182 +
183 + if (pdev->dev.of_node) {
184 + struct device_node *i2s_node;
185 + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_amp_dai[0];
186 + i2s_node = of_parse_phandle(pdev->dev.of_node,
187 + "i2s-controller", 0);
188 +
189 + if (i2s_node) {
190 + dai->cpu_dai_name = NULL;
191 + dai->cpu_of_node = i2s_node;
192 + dai->platform_name = NULL;
193 + dai->platform_of_node = i2s_node;
194 + }
195 + }
196 +
197 + ret = snd_soc_register_card(&snd_rpi_hifiberry_amp);
198 +
199 + if (ret != 0) {
200 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
201 + }
202 +
203 + return ret;
204 +}
205 +
206 +
207 +static int snd_rpi_hifiberry_amp_remove(struct platform_device *pdev)
208 +{
209 + return snd_soc_unregister_card(&snd_rpi_hifiberry_amp);
210 +}
211 +
212 +
213 +static struct platform_driver snd_rpi_hifiberry_amp_driver = {
214 + .driver = {
215 + .name = "snd-hifiberry-amp",
216 + .owner = THIS_MODULE,
217 + .of_match_table = snd_rpi_hifiberry_amp_of_match,
218 + },
219 + .probe = snd_rpi_hifiberry_amp_probe,
220 + .remove = snd_rpi_hifiberry_amp_remove,
221 +};
222 +
223 +
224 +module_platform_driver(snd_rpi_hifiberry_amp_driver);
225 +
226 +
227 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
228 +MODULE_DESCRIPTION("ASoC driver for HiFiBerry-AMP");
229 +MODULE_LICENSE("GPL v2");
230 --- a/sound/soc/codecs/Kconfig
231 +++ b/sound/soc/codecs/Kconfig
232 @@ -109,6 +109,7 @@ config SND_SOC_ALL_CODECS
233 select SND_SOC_TFA9879 if I2C
234 select SND_SOC_TLV320AIC23_I2C if I2C
235 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
236 + select SND_SOC_TAS5713 if I2C
237 select SND_SOC_TLV320AIC26 if SPI_MASTER
238 select SND_SOC_TLV320AIC31XX if I2C
239 select SND_SOC_TLV320AIC32X4 if I2C
240 @@ -623,6 +624,9 @@ config SND_SOC_TFA9879
241 tristate "NXP Semiconductors TFA9879 amplifier"
242 depends on I2C
243
244 +config SND_SOC_TAS5713
245 + tristate
246 +
247 config SND_SOC_TLV320AIC23
248 tristate
249
250 --- a/sound/soc/codecs/Makefile
251 +++ b/sound/soc/codecs/Makefile
252 @@ -109,6 +109,7 @@ snd-soc-sta529-objs := sta529.o
253 snd-soc-stac9766-objs := stac9766.o
254 snd-soc-tas5086-objs := tas5086.o
255 snd-soc-tfa9879-objs := tfa9879.o
256 +snd-soc-tas5713-objs := tas5713.o
257 snd-soc-tlv320aic23-objs := tlv320aic23.o
258 snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
259 snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o
260 @@ -293,6 +294,7 @@ obj-$(CONFIG_SND_SOC_STAC9766) += snd-so
261 obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
262 obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
263 obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
264 +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
265 obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
266 obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
267 obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o
268 --- /dev/null
269 +++ b/sound/soc/codecs/tas5713.c
270 @@ -0,0 +1,369 @@
271 +/*
272 + * ASoC Driver for TAS5713
273 + *
274 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
275 + * Copyright 2014
276 + *
277 + * This program is free software; you can redistribute it and/or
278 + * modify it under the terms of the GNU General Public License
279 + * version 2 as published by the Free Software Foundation.
280 + *
281 + * This program is distributed in the hope that it will be useful, but
282 + * WITHOUT ANY WARRANTY; without even the implied warranty of
283 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
284 + * General Public License for more details.
285 + */
286 +
287 +#include <linux/module.h>
288 +#include <linux/moduleparam.h>
289 +#include <linux/init.h>
290 +#include <linux/delay.h>
291 +#include <linux/pm.h>
292 +#include <linux/i2c.h>
293 +#include <linux/of_device.h>
294 +#include <linux/spi/spi.h>
295 +#include <linux/regmap.h>
296 +#include <linux/regulator/consumer.h>
297 +#include <linux/slab.h>
298 +#include <sound/core.h>
299 +#include <sound/pcm.h>
300 +#include <sound/pcm_params.h>
301 +#include <sound/soc.h>
302 +#include <sound/initval.h>
303 +#include <sound/tlv.h>
304 +
305 +#include <linux/kernel.h>
306 +#include <linux/string.h>
307 +#include <linux/fs.h>
308 +#include <asm/uaccess.h>
309 +
310 +#include "tas5713.h"
311 +
312 +
313 +static struct i2c_client *i2c;
314 +
315 +struct tas5713_priv {
316 + struct regmap *regmap;
317 + int mclk_div;
318 + struct snd_soc_codec *codec;
319 +};
320 +
321 +static struct tas5713_priv *priv_data;
322 +
323 +
324 +
325 +
326 +/*
327 + * _ _ ___ _ ___ _ _
328 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
329 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
330 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
331 + *
332 + */
333 +
334 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
335 +
336 +
337 +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
338 + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
339 + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
340 +};
341 +
342 +
343 +
344 +
345 +/*
346 + * __ __ _ _ ___ _
347 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
348 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
349 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
350 + *
351 + */
352 +
353 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
354 + struct snd_pcm_hw_params *params,
355 + struct snd_soc_dai *dai)
356 +{
357 + u16 blen = 0x00;
358 +
359 + struct snd_soc_codec *codec;
360 + codec = dai->codec;
361 + priv_data->codec = dai->codec;
362 +
363 + switch (params_format(params)) {
364 + case SNDRV_PCM_FORMAT_S16_LE:
365 + blen = 0x03;
366 + break;
367 + case SNDRV_PCM_FORMAT_S20_3LE:
368 + blen = 0x1;
369 + break;
370 + case SNDRV_PCM_FORMAT_S24_LE:
371 + blen = 0x04;
372 + break;
373 + case SNDRV_PCM_FORMAT_S32_LE:
374 + blen = 0x05;
375 + break;
376 + default:
377 + dev_err(dai->dev, "Unsupported word length: %u\n",
378 + params_format(params));
379 + return -EINVAL;
380 + }
381 +
382 + // set word length
383 + snd_soc_update_bits(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
384 +
385 + return 0;
386 +}
387 +
388 +
389 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
390 +{
391 + unsigned int val = 0;
392 +
393 + struct tas5713_priv *tas5713;
394 + struct snd_soc_codec *codec = dai->codec;
395 + tas5713 = snd_soc_codec_get_drvdata(codec);
396 +
397 + if (mute) {
398 + val = TAS5713_SOFT_MUTE_ALL;
399 + }
400 +
401 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
402 +}
403 +
404 +
405 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
406 + .hw_params = tas5713_hw_params,
407 + .mute_stream = tas5713_mute_stream,
408 +};
409 +
410 +
411 +static struct snd_soc_dai_driver tas5713_dai = {
412 + .name = "tas5713-hifi",
413 + .playback = {
414 + .stream_name = "Playback",
415 + .channels_min = 2,
416 + .channels_max = 2,
417 + .rates = SNDRV_PCM_RATE_8000_48000,
418 + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
419 + },
420 + .ops = &tas5713_dai_ops,
421 +};
422 +
423 +
424 +
425 +
426 +/*
427 + * ___ _ ___ _
428 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
429 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
430 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
431 + *
432 + */
433 +
434 +static int tas5713_remove(struct snd_soc_codec *codec)
435 +{
436 + struct tas5713_priv *tas5713;
437 +
438 + tas5713 = snd_soc_codec_get_drvdata(codec);
439 +
440 + return 0;
441 +}
442 +
443 +
444 +static int tas5713_probe(struct snd_soc_codec *codec)
445 +{
446 + struct tas5713_priv *tas5713;
447 + int i, ret;
448 +
449 + i2c = container_of(codec->dev, struct i2c_client, dev);
450 +
451 + tas5713 = snd_soc_codec_get_drvdata(codec);
452 +
453 + // Reset error
454 + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
455 + if (ret < 0) return ret;
456 +
457 + // Trim oscillator
458 + ret = snd_soc_write(codec, TAS5713_OSC_TRIM, 0x00);
459 + if (ret < 0) return ret;
460 + msleep(1000);
461 +
462 + // Reset error
463 + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
464 + if (ret < 0) return ret;
465 +
466 + // Clock mode: 44/48kHz, MCLK=64xfs
467 + ret = snd_soc_write(codec, TAS5713_CLOCK_CTRL, 0x60);
468 + if (ret < 0) return ret;
469 +
470 + // I2S 24bit
471 + ret = snd_soc_write(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
472 + if (ret < 0) return ret;
473 +
474 + // Unmute
475 + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
476 + if (ret < 0) return ret;
477 + ret = snd_soc_write(codec, TAS5713_SOFT_MUTE, 0x00);
478 + if (ret < 0) return ret;
479 +
480 + // Set volume to 0db
481 + ret = snd_soc_write(codec, TAS5713_VOL_MASTER, 0x00);
482 + if (ret < 0) return ret;
483 +
484 + // Now start programming the default initialization sequence
485 + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
486 + ret = i2c_master_send(i2c,
487 + tas5713_init_sequence[i].data,
488 + tas5713_init_sequence[i].size);
489 + if (ret < 0) {
490 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
491 + }
492 + }
493 +
494 + // Unmute
495 + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
496 + if (ret < 0) return ret;
497 +
498 + return 0;
499 +}
500 +
501 +
502 +static struct snd_soc_codec_driver soc_codec_dev_tas5713 = {
503 + .probe = tas5713_probe,
504 + .remove = tas5713_remove,
505 + .controls = tas5713_snd_controls,
506 + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
507 +};
508 +
509 +
510 +
511 +
512 +/*
513 + * ___ ___ ___ ___ _
514 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
515 + * | | / / (__ | |) | '_| \ V / -_) '_|
516 + * |___/___\___| |___/|_| |_|\_/\___|_|
517 + *
518 + */
519 +
520 +static const struct reg_default tas5713_reg_defaults[] = {
521 + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
522 + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
523 + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
524 + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
525 +};
526 +
527 +
528 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
529 +{
530 + switch (reg) {
531 + case TAS5713_DEVICE_ID:
532 + case TAS5713_ERROR_STATUS:
533 + return true;
534 + default:
535 + return false;
536 + }
537 +}
538 +
539 +
540 +static const struct of_device_id tas5713_of_match[] = {
541 + { .compatible = "ti,tas5713", },
542 + { }
543 +};
544 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
545 +
546 +
547 +static struct regmap_config tas5713_regmap_config = {
548 + .reg_bits = 8,
549 + .val_bits = 8,
550 +
551 + .max_register = TAS5713_MAX_REGISTER,
552 + .volatile_reg = tas5713_reg_volatile,
553 +
554 + .cache_type = REGCACHE_RBTREE,
555 + .reg_defaults = tas5713_reg_defaults,
556 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
557 +};
558 +
559 +
560 +static int tas5713_i2c_probe(struct i2c_client *i2c,
561 + const struct i2c_device_id *id)
562 +{
563 + int ret;
564 +
565 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
566 + if (!priv_data)
567 + return -ENOMEM;
568 +
569 + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
570 + if (IS_ERR(priv_data->regmap)) {
571 + ret = PTR_ERR(priv_data->regmap);
572 + return ret;
573 + }
574 +
575 + i2c_set_clientdata(i2c, priv_data);
576 +
577 + ret = snd_soc_register_codec(&i2c->dev,
578 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
579 +
580 + return ret;
581 +}
582 +
583 +
584 +static int tas5713_i2c_remove(struct i2c_client *i2c)
585 +{
586 + snd_soc_unregister_codec(&i2c->dev);
587 + i2c_set_clientdata(i2c, NULL);
588 +
589 + kfree(priv_data);
590 +
591 + return 0;
592 +}
593 +
594 +
595 +static const struct i2c_device_id tas5713_i2c_id[] = {
596 + { "tas5713", 0 },
597 + { }
598 +};
599 +
600 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
601 +
602 +
603 +static struct i2c_driver tas5713_i2c_driver = {
604 + .driver = {
605 + .name = "tas5713",
606 + .owner = THIS_MODULE,
607 + .of_match_table = tas5713_of_match,
608 + },
609 + .probe = tas5713_i2c_probe,
610 + .remove = tas5713_i2c_remove,
611 + .id_table = tas5713_i2c_id
612 +};
613 +
614 +
615 +static int __init tas5713_modinit(void)
616 +{
617 + int ret = 0;
618 +
619 + ret = i2c_add_driver(&tas5713_i2c_driver);
620 + if (ret) {
621 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
622 + ret);
623 + }
624 +
625 + return ret;
626 +}
627 +module_init(tas5713_modinit);
628 +
629 +
630 +static void __exit tas5713_exit(void)
631 +{
632 + i2c_del_driver(&tas5713_i2c_driver);
633 +}
634 +module_exit(tas5713_exit);
635 +
636 +
637 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
638 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
639 +MODULE_LICENSE("GPL v2");
640 --- /dev/null
641 +++ b/sound/soc/codecs/tas5713.h
642 @@ -0,0 +1,210 @@
643 +/*
644 + * ASoC Driver for TAS5713
645 + *
646 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
647 + * Copyright 2014
648 + *
649 + * This program is free software; you can redistribute it and/or
650 + * modify it under the terms of the GNU General Public License
651 + * version 2 as published by the Free Software Foundation.
652 + *
653 + * This program is distributed in the hope that it will be useful, but
654 + * WITHOUT ANY WARRANTY; without even the implied warranty of
655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
656 + * General Public License for more details.
657 + */
658 +
659 +#ifndef _TAS5713_H
660 +#define _TAS5713_H
661 +
662 +
663 +// TAS5713 I2C-bus register addresses
664 +
665 +#define TAS5713_CLOCK_CTRL 0x00
666 +#define TAS5713_DEVICE_ID 0x01
667 +#define TAS5713_ERROR_STATUS 0x02
668 +#define TAS5713_SYSTEM_CTRL1 0x03
669 +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
670 +#define TAS5713_SYSTEM_CTRL2 0x05
671 +#define TAS5713_SOFT_MUTE 0x06
672 +#define TAS5713_VOL_MASTER 0x07
673 +#define TAS5713_VOL_CH1 0x08
674 +#define TAS5713_VOL_CH2 0x09
675 +#define TAS5713_VOL_HEADPHONE 0x0A
676 +#define TAS5713_VOL_CONFIG 0x0E
677 +#define TAS5713_MODULATION_LIMIT 0x10
678 +#define TAS5713_IC_DLY_CH1 0x11
679 +#define TAS5713_IC_DLY_CH2 0x12
680 +#define TAS5713_IC_DLY_CH3 0x13
681 +#define TAS5713_IC_DLY_CH4 0x14
682 +
683 +#define TAS5713_START_STOP_PERIOD 0x1A
684 +#define TAS5713_OSC_TRIM 0x1B
685 +#define TAS5713_BKND_ERR 0x1C
686 +
687 +#define TAS5713_INPUT_MUX 0x20
688 +#define TAS5713_SRC_SELECT_CH4 0x21
689 +#define TAS5713_PWM_MUX 0x25
690 +
691 +#define TAS5713_CH1_BQ0 0x29
692 +#define TAS5713_CH1_BQ1 0x2A
693 +#define TAS5713_CH1_BQ2 0x2B
694 +#define TAS5713_CH1_BQ3 0x2C
695 +#define TAS5713_CH1_BQ4 0x2D
696 +#define TAS5713_CH1_BQ5 0x2E
697 +#define TAS5713_CH1_BQ6 0x2F
698 +#define TAS5713_CH1_BQ7 0x58
699 +#define TAS5713_CH1_BQ8 0x59
700 +
701 +#define TAS5713_CH2_BQ0 0x30
702 +#define TAS5713_CH2_BQ1 0x31
703 +#define TAS5713_CH2_BQ2 0x32
704 +#define TAS5713_CH2_BQ3 0x33
705 +#define TAS5713_CH2_BQ4 0x34
706 +#define TAS5713_CH2_BQ5 0x35
707 +#define TAS5713_CH2_BQ6 0x36
708 +#define TAS5713_CH2_BQ7 0x5C
709 +#define TAS5713_CH2_BQ8 0x5D
710 +
711 +#define TAS5713_CH4_BQ0 0x5A
712 +#define TAS5713_CH4_BQ1 0x5B
713 +#define TAS5713_CH3_BQ0 0x5E
714 +#define TAS5713_CH3_BQ1 0x5F
715 +
716 +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
717 +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
718 +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
719 +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
720 +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
721 +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
722 +#define TAS5713_DRC_CTRL 0x46
723 +
724 +#define TAS5713_BANK_SW_CTRL 0x50
725 +#define TAS5713_CH1_OUTPUT_MIXER 0x51
726 +#define TAS5713_CH2_OUTPUT_MIXER 0x52
727 +#define TAS5713_CH1_INPUT_MIXER 0x53
728 +#define TAS5713_CH2_INPUT_MIXER 0x54
729 +#define TAS5713_OUTPUT_POST_SCALE 0x56
730 +#define TAS5713_OUTPUT_PRESCALE 0x57
731 +
732 +#define TAS5713_IDF_POST_SCALE 0x62
733 +
734 +#define TAS5713_CH1_INLINE_MIXER 0x70
735 +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
736 +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
737 +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
738 +#define TAS5713_CH2_INLINE_MIXER 0x74
739 +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
740 +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
741 +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
742 +
743 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
744 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
745 +
746 +#define TAS5713_REGISTER_COUNT 0x46
747 +#define TAS5713_MAX_REGISTER 0xF9
748 +
749 +
750 +// Bitmasks for registers
751 +#define TAS5713_SOFT_MUTE_ALL 0x07
752 +
753 +
754 +
755 +struct tas5713_init_command {
756 + const int size;
757 + const char *const data;
758 +};
759 +
760 +static const struct tas5713_init_command tas5713_init_sequence[] = {
761 +
762 + // Trim oscillator
763 + { .size = 2, .data = "\x1B\x00" },
764 + // System control register 1 (0x03): block DC
765 + { .size = 2, .data = "\x03\x80" },
766 + // Mute everything
767 + { .size = 2, .data = "\x05\x40" },
768 + // Modulation limit register (0x10): 97.7%
769 + { .size = 2, .data = "\x10\x02" },
770 + // Interchannel delay registers
771 + // (0x11, 0x12, 0x13, and 0x14): BD mode
772 + { .size = 2, .data = "\x11\xB8" },
773 + { .size = 2, .data = "\x12\x60" },
774 + { .size = 2, .data = "\x13\xA0" },
775 + { .size = 2, .data = "\x14\x48" },
776 + // PWM shutdown group register (0x19): no shutdown
777 + { .size = 2, .data = "\x19\x00" },
778 + // Input multiplexer register (0x20): BD mode
779 + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
780 + // PWM output mux register (0x25)
781 + // Channel 1 --> OUTA, channel 1 neg --> OUTB
782 + // Channel 2 --> OUTC, channel 2 neg --> OUTD
783 + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
784 + // DRC control (0x46): DRC off
785 + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
786 + // BKND_ERR register (0x1C): 299ms reset period
787 + { .size = 2, .data = "\x1C\x07" },
788 + // Mute channel 3
789 + { .size = 2, .data = "\x0A\xFF" },
790 + // Volume configuration register (0x0E): volume slew 512 steps
791 + { .size = 2, .data = "\x0E\x90" },
792 + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
793 + { .size = 2, .data = "\x00\x60" },
794 + // Bank switch and eq control (0x50): no bank switching
795 + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
796 + // Volume registers (0x07, 0x08, 0x09, 0x0A)
797 + { .size = 2, .data = "\x07\x20" },
798 + { .size = 2, .data = "\x08\x30" },
799 + { .size = 2, .data = "\x09\x30" },
800 + { .size = 2, .data = "\x0A\xFF" },
801 + // 0x72, 0x73, 0x76, 0x77 input mixer:
802 + // no intermix between channels
803 + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
804 + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
805 + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
806 + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
807 + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
808 + // no inline DRC inmix
809 + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
810 + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
811 + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
812 + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
813 + // 0x56, 0x57 Output scale
814 + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
815 + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
816 + // 0x3B, 0x3c
817 + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
818 + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
819 + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
820 + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
821 + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
822 + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
823 + // 0x51, 0x52: output mixer
824 + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
825 + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
826 + // PEQ defaults
827 + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
828 + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
829 + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
830 + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
831 + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
832 + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
833 + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
834 + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
835 + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
836 + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
837 + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
838 + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
839 + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
840 + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
841 + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
842 + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
843 + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
844 + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
845 + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
846 + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
847 + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
848 + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
849 +};
850 +
851 +
852 +#endif /* _TAS5713_H */