1 From 74de23a947ad5964b25e9f9f15329d3174488fea Mon Sep 17 00:00:00 2001
2 From: Joerg Schambacher <joerg@hifiberry.com>
3 Date: Wed, 6 Oct 2021 17:21:07 +0200
4 Subject: [PATCH] Hifiberry DAC+ADCPro: adding optional headphone amp
7 This is a copy of the code and approach from our DAC+ driver.
8 It allows to probe (and activate) an optional TPA6130A2 headphone
9 amplifier. Updated email address.
11 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
13 sound/soc/bcm/Kconfig | 3 +-
14 sound/soc/bcm/hifiberry_dacplusadcpro.c | 74 ++++++++++++++++++++++++-
15 2 files changed, 73 insertions(+), 4 deletions(-)
17 --- a/sound/soc/bcm/Kconfig
18 +++ b/sound/soc/bcm/Kconfig
19 @@ -79,7 +79,8 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
20 tristate "Support for HifiBerry DAC+ADC PRO"
21 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
22 select SND_SOC_PCM512x_I2C
23 - select SND_SOC_PCM186X_I2C
24 + select SND_SOC_PCM186X_I2C
25 + select SND_SOC_TPA6130A2
26 select COMMON_CLK_HIFIBERRY_DACPRO
28 Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
29 --- a/sound/soc/bcm/hifiberry_dacplusadcpro.c
30 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
32 * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
34 * based on code by Florian Meier <florian.meier@koalo.de>
35 - * ADC added by Joerg Schambacher <joerg@i2audio.com>
37 + * ADC, HP added by Joerg Schambacher <joerg@hifiberry.com>
40 * This program is free software; you can redistribute it and/or
41 * modify it under the terms of the GNU General Public License
44 #include <linux/slab.h>
45 #include <linux/delay.h>
46 +#include <linux/i2c.h>
48 #include <sound/core.h>
49 #include <sound/pcm.h>
50 @@ -468,6 +469,15 @@ static struct snd_soc_dai_link snd_rpi_h
54 +/* aux device for optional headphone amp */
55 +static struct snd_soc_aux_dev hifiberry_dacplusadcpro_aux_devs[] = {
58 + .name = "tpa6130a2.1-0060",
63 /* audio machine driver */
64 static struct snd_soc_card snd_rpi_hifiberry_dacplusadcpro = {
65 .name = "snd_rpi_hifiberry_dacplusadcpro",
66 @@ -477,10 +487,68 @@ static struct snd_soc_card snd_rpi_hifib
67 .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadcpro_dai),
70 +static int hb_hp_detect(void)
72 + struct i2c_adapter *adap = i2c_get_adapter(1);
74 + struct i2c_client tpa_i2c_client = {
80 + return -EPROBE_DEFER; /* I2C module not yet available */
82 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
83 + i2c_put_adapter(adap);
87 +static struct property tpa_enable_prop = {
89 + .length = 4 + 1, /* length 'okay' + 1 */
93 static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
96 struct snd_soc_card *card = &snd_rpi_hifiberry_dacplusadcpro;
97 + struct device_node *tpa_node;
98 + struct property *tpa_prop;
99 + struct of_changeset ocs;
102 + /* probe for head phone amp */
103 + ret = hb_hp_detect();
107 + card->aux_dev = hifiberry_dacplusadcpro_aux_devs;
108 + card->num_aux_devs =
109 + ARRAY_SIZE(hifiberry_dacplusadcpro_aux_devs);
110 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
111 + tpa_prop = of_find_property(tpa_node, "status", &len);
113 + if (strcmp((char *)tpa_prop->value, "okay")) {
114 + /* and activate headphone using change_sets */
115 + dev_info(&pdev->dev, "activating headphone amplifier");
116 + of_changeset_init(&ocs);
117 + ret = of_changeset_update_property(&ocs, tpa_node,
120 + dev_err(&pdev->dev,
121 + "cannot activate headphone amplifier\n");
124 + ret = of_changeset_apply(&ocs);
126 + dev_err(&pdev->dev,
127 + "cannot activate headphone amplifier\n");
133 snd_rpi_hifiberry_dacplusadcpro.dev = &pdev->dev;
134 if (pdev->dev.of_node) {
135 @@ -531,7 +599,7 @@ static struct platform_driver snd_rpi_hi
137 module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
139 -MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
140 +MODULE_AUTHOR("Joerg Schambacher <joerg@hifiberry.com>");
141 MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
142 MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
143 MODULE_LICENSE("GPL v2");