ssm2305.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Analog Devices SSM2305 Amplifier Driver
  4. //
  5. // Copyright (C) 2018 Pengutronix, Marco Felsch <kernel@pengutronix.de>
  6. //
  7. #include <linux/gpio/consumer.h>
  8. #include <linux/module.h>
  9. #include <sound/soc.h>
  10. #define DRV_NAME "ssm2305"
  11. struct ssm2305 {
  12. /* shutdown gpio */
  13. struct gpio_desc *gpiod_shutdown;
  14. };
  15. static int ssm2305_power_event(struct snd_soc_dapm_widget *w,
  16. struct snd_kcontrol *kctrl, int event)
  17. {
  18. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  19. struct ssm2305 *data = snd_soc_component_get_drvdata(c);
  20. gpiod_set_value_cansleep(data->gpiod_shutdown,
  21. SND_SOC_DAPM_EVENT_ON(event));
  22. return 0;
  23. }
  24. static const struct snd_soc_dapm_widget ssm2305_dapm_widgets[] = {
  25. /* Stereo input/output */
  26. SND_SOC_DAPM_INPUT("L_IN"),
  27. SND_SOC_DAPM_INPUT("R_IN"),
  28. SND_SOC_DAPM_OUTPUT("L_OUT"),
  29. SND_SOC_DAPM_OUTPUT("R_OUT"),
  30. SND_SOC_DAPM_SUPPLY("Power", SND_SOC_NOPM, 0, 0, ssm2305_power_event,
  31. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  32. };
  33. static const struct snd_soc_dapm_route ssm2305_dapm_routes[] = {
  34. { "L_OUT", NULL, "L_IN" },
  35. { "R_OUT", NULL, "R_IN" },
  36. { "L_IN", NULL, "Power" },
  37. { "R_IN", NULL, "Power" },
  38. };
  39. static const struct snd_soc_component_driver ssm2305_component_driver = {
  40. .dapm_widgets = ssm2305_dapm_widgets,
  41. .num_dapm_widgets = ARRAY_SIZE(ssm2305_dapm_widgets),
  42. .dapm_routes = ssm2305_dapm_routes,
  43. .num_dapm_routes = ARRAY_SIZE(ssm2305_dapm_routes),
  44. };
  45. static int ssm2305_probe(struct platform_device *pdev)
  46. {
  47. struct device *dev = &pdev->dev;
  48. struct ssm2305 *priv;
  49. int err;
  50. /* Allocate the private data */
  51. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  52. if (!priv)
  53. return -ENOMEM;
  54. platform_set_drvdata(pdev, priv);
  55. /* Get shutdown gpio */
  56. priv->gpiod_shutdown = devm_gpiod_get(dev, "shutdown",
  57. GPIOD_OUT_LOW);
  58. if (IS_ERR(priv->gpiod_shutdown)) {
  59. err = PTR_ERR(priv->gpiod_shutdown);
  60. if (err != -EPROBE_DEFER)
  61. dev_err(dev, "Failed to get 'shutdown' gpio: %d\n",
  62. err);
  63. return err;
  64. }
  65. return devm_snd_soc_register_component(dev, &ssm2305_component_driver,
  66. NULL, 0);
  67. }
  68. #ifdef CONFIG_OF
  69. static const struct of_device_id ssm2305_of_match[] = {
  70. { .compatible = "adi,ssm2305", },
  71. { }
  72. };
  73. MODULE_DEVICE_TABLE(of, ssm2305_of_match);
  74. #endif
  75. static struct platform_driver ssm2305_driver = {
  76. .driver = {
  77. .name = DRV_NAME,
  78. .of_match_table = of_match_ptr(ssm2305_of_match),
  79. },
  80. .probe = ssm2305_probe,
  81. };
  82. module_platform_driver(ssm2305_driver);
  83. MODULE_DESCRIPTION("ASoC SSM2305 amplifier driver");
  84. MODULE_AUTHOR("Marco Felsch <m.felsch@pengutronix.de>");
  85. MODULE_LICENSE("GPL v2");