1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/gpio/consumer.h>
4 #include <linux/module.h>
5 #include <linux/regulator/consumer.h>
9 struct gpio_desc *gpiod_mode;
13 static int aw8738_drv_event(struct snd_soc_dapm_widget *w,
14 struct snd_kcontrol *kcontrol, int event)
16 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
17 struct aw8738_priv *aw = snd_soc_component_get_drvdata(c);
21 case SND_SOC_DAPM_POST_PMU:
22 for (i = 0; i < aw->mode; i++) {
23 gpiod_set_value_cansleep(aw->gpiod_mode, 0);
25 gpiod_set_value_cansleep(aw->gpiod_mode, 1);
30 case SND_SOC_DAPM_PRE_PMD:
31 gpiod_set_value_cansleep(aw->gpiod_mode, 0);
32 usleep_range(1000, 2000);
35 WARN(1, "Unexpected event");
42 static const struct snd_soc_dapm_widget aw8738_dapm_widgets[] = {
43 SND_SOC_DAPM_INPUT("IN"),
44 SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, aw8738_drv_event,
45 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
46 SND_SOC_DAPM_OUTPUT("OUT"),
49 static const struct snd_soc_dapm_route aw8738_dapm_routes[] = {
50 { "DRV", NULL, "IN" },
51 { "OUT", NULL, "DRV" },
54 static const struct snd_soc_component_driver aw8738_component_driver = {
55 .dapm_widgets = aw8738_dapm_widgets,
56 .num_dapm_widgets = ARRAY_SIZE(aw8738_dapm_widgets),
57 .dapm_routes = aw8738_dapm_routes,
58 .num_dapm_routes = ARRAY_SIZE(aw8738_dapm_routes),
61 static int aw8738_probe(struct platform_device *pdev)
63 struct device *dev = &pdev->dev;
64 struct aw8738_priv *aw;
67 aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL);
70 platform_set_drvdata(pdev, aw);
72 aw->gpiod_mode = devm_gpiod_get(dev, "mode", GPIOD_OUT_LOW);
73 if (IS_ERR(aw->gpiod_mode))
74 return dev_err_probe(dev, PTR_ERR(aw->gpiod_mode),
75 "Failed to get 'mode' gpio");
77 ret = device_property_read_u32(dev, "awinic,mode", &aw->mode);
81 return devm_snd_soc_register_component(&pdev->dev,
82 &aw8738_component_driver,
87 static const struct of_device_id aw8738_of_match[] = {
88 { .compatible = "awinic,aw8738" },
91 MODULE_DEVICE_TABLE(of, aw8738_of_match);
94 static struct platform_driver aw8738_driver = {
95 .probe = aw8738_probe,
98 .of_match_table = of_match_ptr(aw8738_of_match),
101 module_platform_driver(aw8738_driver);
103 MODULE_DESCRIPTION("Awinic AW8738 Amplifier Driver");
104 MODULE_LICENSE("GPL v2");