Skip to content

Commit

Permalink
general-enhance-backport-es8328-driver(:1)
Browse files Browse the repository at this point in the history
Original-Subject: [ARCHEOLOGY] fix analog sound station-p1 (#3166)
> X-Git-Archeology: - Revision b2d54059f75ae69b71a6a422c178ceef271336f1: armbian/build@b2d5405
> X-Git-Archeology:   Date: Thu, 07 Oct 2021 16:48:09 +0200
> X-Git-Archeology:   From: Oleg <balbes-150@yandex.ru>
> X-Git-Archeology:   Subject: fix analog sound station-p1 (#3166)
> X-Git-Archeology: 
> X-Git-Archeology: - Revision 92f1a22d76b987afa7ba555d5b509adc51d689e7: armbian/build@92f1a22
> X-Git-Archeology:   Date: Fri, 16 Dec 2022 13:38:13 +0100
> X-Git-Archeology:   From: Igor Pecovnik <igorpecovnik@users.noreply.github.com>
> X-Git-Archeology:   Subject: Re-add rockchip64 6.0 patches (#4575)
> X-Git-Archeology: 
X-Armbian: Patch-File: general-enhance-backport-es8328-driver
X-Armbian: Patch-File-Counter: 1
X-Armbian: Patch-Rel-Directory: patch/kernel/archive/rockchip64-6.1
X-Armbian: Patch-Type: kernel
X-Armbian: Patch-Root-Type: core
X-Armbian: Patch-Sub-Type: common
X-Armbian: Original-Subject: [ARCHEOLOGY] fix analog sound station-p1 (#3166)
  • Loading branch information
150balbes authored and Armbian AutoPatcher committed Oct 7, 2021
1 parent 6c3bff3 commit 855629d
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions sound/soc/codecs/es8328.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/tlv.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>
#include "es8328.h"

#define INVALID_GPIO -1
#define ES8328_CODEC_SET_HP 1

static const unsigned int rates_12288[] = {
8000, 12000, 16000, 24000, 32000, 48000, 96000,
};
Expand Down Expand Up @@ -86,8 +91,18 @@ struct es8328_priv {
const int *mclk_ratios;
bool provider;
struct regulator_bulk_data supplies[ES8328_SUPPLY_NUM];

int hp_ctl_gpio;
int hp_det_gpio;

bool muted;
bool hp_inserted;
bool hp_gpio_level;
bool hp_det_level;
};

static struct es8328_priv *es8328_private;

/*
* ES8328 Controls
*/
Expand All @@ -112,6 +127,42 @@ static const struct {
{ 48000, ES8328_DACCONTROL6_DEEMPH_48k },
};

static int es8328_set_gpio(int gpio, bool level)
{
struct es8328_priv *es8328 = es8328_private;

if (!es8328) {
return 0;
}

if ((gpio & ES8328_CODEC_SET_HP) && es8328
&& es8328->hp_ctl_gpio != INVALID_GPIO) {
gpio_set_value(es8328->hp_ctl_gpio, level);
}

return 0;
}

static irqreturn_t hp_det_irq_handler(int irq, void *dev_id)
{
struct es8328_priv *es8328 = es8328_private;

if(gpio_get_value(es8328->hp_det_gpio)) {
es8328->hp_inserted = 1;
} else {
es8328->hp_inserted = 0;
}

if(!es8328->muted && es8328->hp_inserted) {
es8328_set_gpio(ES8328_CODEC_SET_HP, es8328->hp_gpio_level);
} else {
es8328_set_gpio(ES8328_CODEC_SET_HP, !es8328->hp_gpio_level);
}
return IRQ_HANDLED;
}



static int es8328_set_deemph(struct snd_soc_component *component)
{
struct es8328_priv *es8328 = snd_soc_component_get_drvdata(component);
Expand Down Expand Up @@ -454,6 +505,14 @@ static const struct snd_soc_dapm_route es8328_dapm_routes[] = {

static int es8328_mute(struct snd_soc_dai *dai, int mute, int direction)
{
struct es8328_priv *es8328 = snd_soc_component_get_drvdata(dai->component);
es8328->muted = mute;
if (!mute && es8328->hp_inserted) {
es8328_set_gpio(ES8328_CODEC_SET_HP, es8328->hp_gpio_level);
} else {
es8328_set_gpio(ES8328_CODEC_SET_HP, !es8328->hp_gpio_level);
}

return snd_soc_component_update_bits(dai->component, ES8328_DACCONTROL3,
ES8328_DACCONTROL3_DACMUTE,
mute ? ES8328_DACCONTROL3_DACMUTE : 0);
Expand Down Expand Up @@ -798,6 +857,21 @@ static int es8328_component_probe(struct snd_soc_component *component)
goto clk_fail;
}

if (es8328->hp_det_gpio != INVALID_GPIO) {
if (gpio_get_value(es8328->hp_det_gpio) == es8328->hp_det_level)
es8328->hp_inserted = 1;
} else {
es8328->hp_inserted = 1;
}


if (!strncmp(component->dev->of_node->name, "es8388", 6)) {
usleep_range(18000, 20000);
snd_soc_component_update_bits(component, ES8328_DACCONTROL17,
ES8328_DACCONTROL17_LD2LO, ES8328_DACCONTROL17_LD2LO);
snd_soc_component_update_bits(component, ES8328_DACCONTROL20,
ES8328_DACCONTROL20_RD2RO, ES8328_DACCONTROL20_RD2RO);
}
return 0;

clk_fail:
Expand Down Expand Up @@ -851,6 +925,8 @@ int es8328_probe(struct device *dev, struct regmap *regmap)
struct es8328_priv *es8328;
int ret;
int i;
int hp_irq = 0;
enum of_gpio_flags flags;

if (IS_ERR(regmap))
return PTR_ERR(regmap);
Expand All @@ -860,6 +936,7 @@ int es8328_probe(struct device *dev, struct regmap *regmap)
return -ENOMEM;

es8328->regmap = regmap;
es8328_private = es8328;

for (i = 0; i < ARRAY_SIZE(es8328->supplies); i++)
es8328->supplies[i].supply = supply_names[i];
Expand All @@ -871,6 +948,43 @@ int es8328_probe(struct device *dev, struct regmap *regmap)
return ret;
}

es8328->hp_ctl_gpio = of_get_named_gpio_flags(dev->of_node, "hp-ctl-gpio", 0, &flags);
if (es8328->hp_ctl_gpio < 0) {
dev_info(dev, "Can not read property hp_ctl_gpio\n");
es8328->hp_ctl_gpio = INVALID_GPIO;
} else {
es8328->hp_gpio_level = (flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
ret = devm_gpio_request_one(dev, es8328->hp_ctl_gpio, GPIOF_DIR_OUT, "hp_ctl_gpio");
if (ret != 0) {
dev_err(dev, "Failed to request hp_ctl_gpio\n");
return ret;
}
es8328_set_gpio(ES8328_CODEC_SET_HP, !es8328->hp_gpio_level);
}

es8328->hp_det_gpio = of_get_named_gpio_flags(dev->of_node, "hp-det-gpio", 0, &flags);
if (es8328->hp_det_gpio < 0) {
dev_info(dev, "Can not read property hp_det_gpio\n");
es8328->hp_det_gpio = INVALID_GPIO;
} else {
es8328->hp_det_level = (flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
ret = devm_gpio_request_one(dev, es8328->hp_det_gpio, GPIOF_IN, NULL);
if (ret != 0) {
dev_err(dev, "Failed to request hp_det_gpio\n");
return ret;
}
hp_irq = gpio_to_irq(es8328->hp_det_gpio);

if (hp_irq) {
ret = devm_request_threaded_irq(dev, hp_irq, NULL, hp_det_irq_handler,
IRQ_TYPE_EDGE_BOTH | IRQF_ONESHOT, "ES8323", NULL);
if (ret < 0) {
dev_err(dev, "request_irq failed: %d\n", ret);
return ret;
}
}
}

dev_set_drvdata(dev, es8328);

return devm_snd_soc_register_component(dev,
Expand Down

0 comments on commit 855629d

Please sign in to comment.