Skip to content

Commit a149377

Browse files
tokyovigilantebroonie
authored andcommitted
ASoC: sun4i-codec: support hp-det-gpios property
Add support for GPIO headphone detection with the hp-det-gpios property. In order for this to properly disable the path upon removal of headphones, the output must be labelled Headphone which is a common sink in the driver. Describe a headphone jack and detection GPIO in the driver, check for a corresponding device tree node, and enable jack detection in a new machine init function if described. Signed-off-by: Chris Morgan <[email protected]> Signed-off-by: Ryan Walklin <[email protected]> -- Changelog v1..v2: - Separate DAPM changes into separate patch and add rationale. Tested-by: Philippe Simons <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ae5f76d commit a149377

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

sound/soc/sunxi/sun4i-codec.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/gpio/consumer.h>
2323

2424
#include <sound/core.h>
25+
#include <sound/jack.h>
2526
#include <sound/pcm.h>
2627
#include <sound/pcm_params.h>
2728
#include <sound/soc.h>
@@ -331,6 +332,7 @@ struct sun4i_codec {
331332
struct clk *clk_module;
332333
struct reset_control *rst;
333334
struct gpio_desc *gpio_pa;
335+
struct gpio_desc *gpio_hp;
334336

335337
/* ADC_FIFOC register is at different offset on different SoCs */
336338
struct regmap_field *reg_adc_fifoc;
@@ -1583,6 +1585,49 @@ static struct snd_soc_dai_driver dummy_cpu_dai = {
15831585
.ops = &dummy_dai_ops,
15841586
};
15851587

1588+
static struct snd_soc_jack sun4i_headphone_jack;
1589+
1590+
static struct snd_soc_jack_pin sun4i_headphone_jack_pins[] = {
1591+
{ .pin = "Headphone", .mask = SND_JACK_HEADPHONE },
1592+
};
1593+
1594+
static struct snd_soc_jack_gpio sun4i_headphone_jack_gpio = {
1595+
.name = "hp-det",
1596+
.report = SND_JACK_HEADPHONE,
1597+
.debounce_time = 150,
1598+
};
1599+
1600+
static int sun4i_codec_machine_init(struct snd_soc_pcm_runtime *rtd)
1601+
{
1602+
struct snd_soc_card *card = rtd->card;
1603+
struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card);
1604+
int ret;
1605+
1606+
if (scodec->gpio_hp) {
1607+
ret = snd_soc_card_jack_new_pins(card, "Headphone Jack",
1608+
SND_JACK_HEADPHONE,
1609+
&sun4i_headphone_jack,
1610+
sun4i_headphone_jack_pins,
1611+
ARRAY_SIZE(sun4i_headphone_jack_pins));
1612+
if (ret) {
1613+
dev_err(rtd->dev,
1614+
"Headphone jack creation failed: %d\n", ret);
1615+
return ret;
1616+
}
1617+
1618+
sun4i_headphone_jack_gpio.desc = scodec->gpio_hp;
1619+
ret = snd_soc_jack_add_gpios(&sun4i_headphone_jack, 1,
1620+
&sun4i_headphone_jack_gpio);
1621+
1622+
if (ret) {
1623+
dev_err(rtd->dev, "Headphone GPIO not added: %d\n", ret);
1624+
return ret;
1625+
}
1626+
}
1627+
1628+
return 0;
1629+
}
1630+
15861631
static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev,
15871632
int *num_links)
15881633
{
@@ -1608,6 +1653,7 @@ static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev,
16081653
link->codecs->name = dev_name(dev);
16091654
link->platforms->name = dev_name(dev);
16101655
link->dai_fmt = SND_SOC_DAIFMT_I2S;
1656+
link->init = sun4i_codec_machine_init;
16111657

16121658
*num_links = 1;
16131659

@@ -2302,6 +2348,13 @@ static int sun4i_codec_probe(struct platform_device *pdev)
23022348
return ret;
23032349
}
23042350

2351+
scodec->gpio_hp = devm_gpiod_get_optional(&pdev->dev, "hp-det", GPIOD_IN);
2352+
if (IS_ERR(scodec->gpio_hp)) {
2353+
ret = PTR_ERR(scodec->gpio_hp);
2354+
dev_err_probe(&pdev->dev, ret, "Failed to get hp-det gpio\n");
2355+
return ret;
2356+
}
2357+
23052358
/* reg_field setup */
23062359
scodec->reg_adc_fifoc = devm_regmap_field_alloc(&pdev->dev,
23072360
scodec->regmap,

0 commit comments

Comments
 (0)