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