Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // Analog Devices SSM2305 Amplifier Driver
0004 //
0005 // Copyright (C) 2018 Pengutronix, Marco Felsch <kernel@pengutronix.de>
0006 //
0007 
0008 #include <linux/gpio/consumer.h>
0009 #include <linux/module.h>
0010 #include <sound/soc.h>
0011 
0012 #define DRV_NAME "ssm2305"
0013 
0014 struct ssm2305 {
0015     /* shutdown gpio  */
0016     struct gpio_desc *gpiod_shutdown;
0017 };
0018 
0019 static int ssm2305_power_event(struct snd_soc_dapm_widget *w,
0020                    struct snd_kcontrol *kctrl, int event)
0021 {
0022     struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
0023     struct ssm2305 *data = snd_soc_component_get_drvdata(c);
0024 
0025     gpiod_set_value_cansleep(data->gpiod_shutdown,
0026                  SND_SOC_DAPM_EVENT_ON(event));
0027 
0028     return 0;
0029 }
0030 
0031 static const struct snd_soc_dapm_widget ssm2305_dapm_widgets[] = {
0032     /* Stereo input/output */
0033     SND_SOC_DAPM_INPUT("L_IN"),
0034     SND_SOC_DAPM_INPUT("R_IN"),
0035     SND_SOC_DAPM_OUTPUT("L_OUT"),
0036     SND_SOC_DAPM_OUTPUT("R_OUT"),
0037 
0038     SND_SOC_DAPM_SUPPLY("Power", SND_SOC_NOPM, 0, 0, ssm2305_power_event,
0039                 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
0040 };
0041 
0042 static const struct snd_soc_dapm_route ssm2305_dapm_routes[] = {
0043     { "L_OUT", NULL, "L_IN" },
0044     { "R_OUT", NULL, "R_IN" },
0045     { "L_IN", NULL, "Power" },
0046     { "R_IN", NULL, "Power" },
0047 };
0048 
0049 static const struct snd_soc_component_driver ssm2305_component_driver = {
0050     .dapm_widgets       = ssm2305_dapm_widgets,
0051     .num_dapm_widgets   = ARRAY_SIZE(ssm2305_dapm_widgets),
0052     .dapm_routes        = ssm2305_dapm_routes,
0053     .num_dapm_routes    = ARRAY_SIZE(ssm2305_dapm_routes),
0054 };
0055 
0056 static int ssm2305_probe(struct platform_device *pdev)
0057 {
0058     struct device *dev = &pdev->dev;
0059     struct ssm2305 *priv;
0060 
0061     /* Allocate the private data */
0062     priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0063     if (!priv)
0064         return -ENOMEM;
0065 
0066     platform_set_drvdata(pdev, priv);
0067 
0068     /* Get shutdown gpio */
0069     priv->gpiod_shutdown = devm_gpiod_get(dev, "shutdown",
0070                           GPIOD_OUT_LOW);
0071     if (IS_ERR(priv->gpiod_shutdown))
0072         return dev_err_probe(dev, PTR_ERR(priv->gpiod_shutdown),
0073                      "Failed to get 'shutdown' gpio\n");
0074 
0075     return devm_snd_soc_register_component(dev, &ssm2305_component_driver,
0076                            NULL, 0);
0077 }
0078 
0079 #ifdef CONFIG_OF
0080 static const struct of_device_id ssm2305_of_match[] = {
0081     { .compatible = "adi,ssm2305", },
0082     { }
0083 };
0084 MODULE_DEVICE_TABLE(of, ssm2305_of_match);
0085 #endif
0086 
0087 static struct platform_driver ssm2305_driver = {
0088     .driver = {
0089         .name = DRV_NAME,
0090         .of_match_table = of_match_ptr(ssm2305_of_match),
0091     },
0092     .probe = ssm2305_probe,
0093 };
0094 
0095 module_platform_driver(ssm2305_driver);
0096 
0097 MODULE_DESCRIPTION("ASoC SSM2305 amplifier driver");
0098 MODULE_AUTHOR("Marco Felsch <m.felsch@pengutronix.de>");
0099 MODULE_LICENSE("GPL v2");