0001
0002
0003 #include <linux/gpio/consumer.h>
0004 #include <linux/module.h>
0005 #include <linux/regulator/consumer.h>
0006 #include <sound/soc.h>
0007
0008 struct aw8738_priv {
0009 struct gpio_desc *gpiod_mode;
0010 unsigned int mode;
0011 };
0012
0013 static int aw8738_drv_event(struct snd_soc_dapm_widget *w,
0014 struct snd_kcontrol *kcontrol, int event)
0015 {
0016 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
0017 struct aw8738_priv *aw = snd_soc_component_get_drvdata(c);
0018 int i;
0019
0020 switch (event) {
0021 case SND_SOC_DAPM_POST_PMU:
0022 for (i = 0; i < aw->mode; i++) {
0023 gpiod_set_value_cansleep(aw->gpiod_mode, 0);
0024 udelay(2);
0025 gpiod_set_value_cansleep(aw->gpiod_mode, 1);
0026 udelay(2);
0027 }
0028 msleep(40);
0029 break;
0030 case SND_SOC_DAPM_PRE_PMD:
0031 gpiod_set_value_cansleep(aw->gpiod_mode, 0);
0032 usleep_range(1000, 2000);
0033 break;
0034 default:
0035 WARN(1, "Unexpected event");
0036 return -EINVAL;
0037 }
0038
0039 return 0;
0040 }
0041
0042 static const struct snd_soc_dapm_widget aw8738_dapm_widgets[] = {
0043 SND_SOC_DAPM_INPUT("IN"),
0044 SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, aw8738_drv_event,
0045 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
0046 SND_SOC_DAPM_OUTPUT("OUT"),
0047 };
0048
0049 static const struct snd_soc_dapm_route aw8738_dapm_routes[] = {
0050 { "DRV", NULL, "IN" },
0051 { "OUT", NULL, "DRV" },
0052 };
0053
0054 static const struct snd_soc_component_driver aw8738_component_driver = {
0055 .dapm_widgets = aw8738_dapm_widgets,
0056 .num_dapm_widgets = ARRAY_SIZE(aw8738_dapm_widgets),
0057 .dapm_routes = aw8738_dapm_routes,
0058 .num_dapm_routes = ARRAY_SIZE(aw8738_dapm_routes),
0059 };
0060
0061 static int aw8738_probe(struct platform_device *pdev)
0062 {
0063 struct device *dev = &pdev->dev;
0064 struct aw8738_priv *aw;
0065 int ret;
0066
0067 aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL);
0068 if (!aw)
0069 return -ENOMEM;
0070 platform_set_drvdata(pdev, aw);
0071
0072 aw->gpiod_mode = devm_gpiod_get(dev, "mode", GPIOD_OUT_LOW);
0073 if (IS_ERR(aw->gpiod_mode))
0074 return dev_err_probe(dev, PTR_ERR(aw->gpiod_mode),
0075 "Failed to get 'mode' gpio");
0076
0077 ret = device_property_read_u32(dev, "awinic,mode", &aw->mode);
0078 if (ret)
0079 return -EINVAL;
0080
0081 return devm_snd_soc_register_component(&pdev->dev,
0082 &aw8738_component_driver,
0083 NULL, 0);
0084 }
0085
0086 #ifdef CONFIG_OF
0087 static const struct of_device_id aw8738_of_match[] = {
0088 { .compatible = "awinic,aw8738" },
0089 { }
0090 };
0091 MODULE_DEVICE_TABLE(of, aw8738_of_match);
0092 #endif
0093
0094 static struct platform_driver aw8738_driver = {
0095 .probe = aw8738_probe,
0096 .driver = {
0097 .name = "aw8738",
0098 .of_match_table = of_match_ptr(aw8738_of_match),
0099 },
0100 };
0101 module_platform_driver(aw8738_driver);
0102
0103 MODULE_DESCRIPTION("Awinic AW8738 Amplifier Driver");
0104 MODULE_LICENSE("GPL v2");