1 From defa915bf0acf6ab5e56997a6733546c33f87682 Mon Sep 17 00:00:00 2001
2 From: Joerg Schambacher <joerg@i2audio.com>
3 Date: Tue, 7 Jul 2020 15:09:06 +0200
4 Subject: [PATCH] Enhances the DAC+ driver to control the optional
7 Probes on the I2C bus for TPA6130A2, if successful, it sets DT-parameter
8 'status' from 'disabled' to 'okay' using change_sets to enable
11 Signed-off-by: Joerg Schambacher joerg@i2audio.com
13 sound/soc/bcm/Kconfig | 1 +
14 sound/soc/bcm/hifiberry_dacplus.c | 68 ++++++++++++++++++++++++++++++-
15 2 files changed, 67 insertions(+), 2 deletions(-)
17 --- a/sound/soc/bcm/Kconfig
18 +++ b/sound/soc/bcm/Kconfig
19 @@ -38,6 +38,7 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
20 tristate "Support for HifiBerry DAC+"
21 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
22 select SND_SOC_PCM512x
23 + select SND_SOC_TPA6130A2
24 select COMMON_CLK_HIFIBERRY_DACPRO
26 Say Y or M if you want to add support for HifiBerry DAC+.
27 --- a/sound/soc/bcm/hifiberry_dacplus.c
28 +++ b/sound/soc/bcm/hifiberry_dacplus.c
30 * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
32 * based on code by Florian Meier <florian.meier@koalo.de>
33 + * Headphone added by Joerg Schambacher, joerg@i2audio.com
35 * This program is free software; you can redistribute it and/or
36 * modify it under the terms of the GNU General Public License
39 #include <linux/slab.h>
40 #include <linux/delay.h>
41 +#include <linux/i2c.h>
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 @@ -177,8 +179,7 @@ static int snd_rpi_hifiberry_dacplus_ini
47 snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
49 - if (digital_gain_0db_limit)
51 + if (digital_gain_0db_limit) {
53 struct snd_soc_card *card = rtd->card;
55 @@ -292,6 +293,15 @@ static struct snd_soc_dai_link snd_rpi_h
59 +/* aux device for optional headphone amp */
60 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
63 + .name = "tpa6130a2.1-0060",
68 /* audio machine driver */
69 static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
70 .name = "snd_rpi_hifiberry_dacplus",
71 @@ -301,9 +311,63 @@ static struct snd_soc_card snd_rpi_hifib
72 .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
75 +static int hb_hp_detect(void)
77 + struct i2c_adapter *adap = i2c_get_adapter(1);
80 + struct i2c_client tpa_i2c_client = {
85 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
86 + i2c_put_adapter(adap);
90 +static struct property tpa_enable_prop = {
92 + .length = 4 + 1, /* length 'okay' + 1 */
96 static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
99 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
101 + struct device_node *tpa_node;
102 + struct property *tpa_prop;
103 + struct of_changeset ocs;
105 + /* probe for head phone amp */
106 + if (hb_hp_detect()) {
107 + card->aux_dev = hifiberry_dacplus_aux_devs;
108 + card->num_aux_devs =
109 + ARRAY_SIZE(hifiberry_dacplus_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_dacplus.dev = &pdev->dev;
134 if (pdev->dev.of_node) {