kernel: bump 5.4 to 5.4.106
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0883-Enhances-the-DAC-driver-to-control-the-optional-head.patch
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
5 headphone amplifier
6
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
9 the headphone control.
10
11 Signed-off-by: Joerg Schambacher joerg@i2audio.com
12 ---
13 sound/soc/bcm/Kconfig | 1 +
14 sound/soc/bcm/hifiberry_dacplus.c | 68 ++++++++++++++++++++++++++++++-
15 2 files changed, 67 insertions(+), 2 deletions(-)
16
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
25 help
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
29 @@ -4,6 +4,7 @@
30 * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
31 * Copyright 2014-2015
32 * based on code by Florian Meier <florian.meier@koalo.de>
33 + * Headphone added by Joerg Schambacher, joerg@i2audio.com
34 *
35 * This program is free software; you can redistribute it and/or
36 * modify it under the terms of the GNU General Public License
37 @@ -24,6 +25,7 @@
38 #include <linux/of.h>
39 #include <linux/slab.h>
40 #include <linux/delay.h>
41 +#include <linux/i2c.h>
42
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 @@ -177,8 +179,7 @@ static int snd_rpi_hifiberry_dacplus_ini
46 else
47 snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
48
49 - if (digital_gain_0db_limit)
50 - {
51 + if (digital_gain_0db_limit) {
52 int ret;
53 struct snd_soc_card *card = rtd->card;
54
55 @@ -292,6 +293,15 @@ static struct snd_soc_dai_link snd_rpi_h
56 },
57 };
58
59 +/* aux device for optional headphone amp */
60 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
61 + {
62 + .dlc = {
63 + .name = "tpa6130a2.1-0060",
64 + },
65 + },
66 +};
67 +
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),
73 };
74
75 +static int hb_hp_detect(void)
76 +{
77 + struct i2c_adapter *adap = i2c_get_adapter(1);
78 + int ret;
79 +
80 + struct i2c_client tpa_i2c_client = {
81 + .addr = 0x60,
82 + .adapter = adap,
83 + };
84 +
85 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
86 + i2c_put_adapter(adap);
87 + return ret;
88 +};
89 +
90 +static struct property tpa_enable_prop = {
91 + .name = "status",
92 + .length = 4 + 1, /* length 'okay' + 1 */
93 + .value = "okay",
94 + };
95 +
96 static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
97 {
98 int ret = 0;
99 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
100 + int len;
101 + struct device_node *tpa_node;
102 + struct property *tpa_prop;
103 + struct of_changeset ocs;
104 +
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);
112 +
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,
118 + &tpa_enable_prop);
119 + if (ret) {
120 + dev_err(&pdev->dev,
121 + "cannot activate headphone amplifier\n");
122 + return -ENODEV;
123 + }
124 + ret = of_changeset_apply(&ocs);
125 + if (ret) {
126 + dev_err(&pdev->dev,
127 + "cannot activate headphone amplifier\n");
128 + return -ENODEV;
129 + }
130 + }
131 + }
132
133 snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
134 if (pdev->dev.of_node) {