forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASoC: codecs: Add Awinic AW8738 audio amplifier driver
The Awinic AW8738 is a simple audio amplifier using a single GPIO. The main difference to simple-amplifier is that there is a "one-wire pulse control" that allows configuring the amplifier to one of a few pre-defined modes. This can be used to configure the speaker-guard function (primarily the power limit for the amplifier). Add a simple driver that allows setting it up in the device tree with a specified mode number. Signed-off-by: Jonathan Albrieux <[email protected]> Co-developed-by: Stephan Gerhold <[email protected]> Signed-off-by: Stephan Gerhold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#include <linux/gpio/consumer.h> | ||
#include <linux/module.h> | ||
#include <linux/regulator/consumer.h> | ||
#include <sound/soc.h> | ||
|
||
struct aw8738_priv { | ||
struct gpio_desc *gpiod_mode; | ||
unsigned int mode; | ||
}; | ||
|
||
static int aw8738_drv_event(struct snd_soc_dapm_widget *w, | ||
struct snd_kcontrol *kcontrol, int event) | ||
{ | ||
struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm); | ||
struct aw8738_priv *aw = snd_soc_component_get_drvdata(c); | ||
int i; | ||
|
||
switch (event) { | ||
case SND_SOC_DAPM_POST_PMU: | ||
for (i = 0; i < aw->mode; i++) { | ||
gpiod_set_value_cansleep(aw->gpiod_mode, 0); | ||
udelay(2); | ||
gpiod_set_value_cansleep(aw->gpiod_mode, 1); | ||
udelay(2); | ||
} | ||
msleep(40); | ||
break; | ||
case SND_SOC_DAPM_PRE_PMD: | ||
gpiod_set_value_cansleep(aw->gpiod_mode, 0); | ||
usleep_range(1000, 2000); | ||
break; | ||
default: | ||
WARN(1, "Unexpected event"); | ||
return -EINVAL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static const struct snd_soc_dapm_widget aw8738_dapm_widgets[] = { | ||
SND_SOC_DAPM_INPUT("IN"), | ||
SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, aw8738_drv_event, | ||
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
SND_SOC_DAPM_OUTPUT("OUT"), | ||
}; | ||
|
||
static const struct snd_soc_dapm_route aw8738_dapm_routes[] = { | ||
{ "DRV", NULL, "IN" }, | ||
{ "OUT", NULL, "DRV" }, | ||
}; | ||
|
||
static const struct snd_soc_component_driver aw8738_component_driver = { | ||
.dapm_widgets = aw8738_dapm_widgets, | ||
.num_dapm_widgets = ARRAY_SIZE(aw8738_dapm_widgets), | ||
.dapm_routes = aw8738_dapm_routes, | ||
.num_dapm_routes = ARRAY_SIZE(aw8738_dapm_routes), | ||
}; | ||
|
||
static int aw8738_probe(struct platform_device *pdev) | ||
{ | ||
struct device *dev = &pdev->dev; | ||
struct aw8738_priv *aw; | ||
int ret; | ||
|
||
aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL); | ||
if (!aw) | ||
return -ENOMEM; | ||
platform_set_drvdata(pdev, aw); | ||
|
||
aw->gpiod_mode = devm_gpiod_get(dev, "mode", GPIOD_OUT_LOW); | ||
if (IS_ERR(aw->gpiod_mode)) | ||
return dev_err_probe(dev, PTR_ERR(aw->gpiod_mode), | ||
"Failed to get 'mode' gpio"); | ||
|
||
ret = device_property_read_u32(dev, "awinic,mode", &aw->mode); | ||
if (ret) | ||
return -EINVAL; | ||
|
||
return devm_snd_soc_register_component(&pdev->dev, | ||
&aw8738_component_driver, | ||
NULL, 0); | ||
} | ||
|
||
#ifdef CONFIG_OF | ||
static const struct of_device_id aw8738_of_match[] = { | ||
{ .compatible = "awinic,aw8738" }, | ||
{ } | ||
}; | ||
MODULE_DEVICE_TABLE(of, aw8738_of_match); | ||
#endif | ||
|
||
static struct platform_driver aw8738_driver = { | ||
.probe = aw8738_probe, | ||
.driver = { | ||
.name = "aw8738", | ||
.of_match_table = of_match_ptr(aw8738_of_match), | ||
}, | ||
}; | ||
module_platform_driver(aw8738_driver); | ||
|
||
MODULE_DESCRIPTION("Awinic AW8738 Amplifier Driver"); | ||
MODULE_LICENSE("GPL v2"); |