xref: /linux/sound/soc/codecs/ssm2305.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
174f24d87SMarco Felsch // SPDX-License-Identifier: GPL-2.0
2d460a2eaSMarco Felsch //
3d460a2eaSMarco Felsch // Analog Devices SSM2305 Amplifier Driver
4d460a2eaSMarco Felsch //
5d460a2eaSMarco Felsch // Copyright (C) 2018 Pengutronix, Marco Felsch <kernel@pengutronix.de>
6d460a2eaSMarco Felsch //
774f24d87SMarco Felsch 
874f24d87SMarco Felsch #include <linux/gpio/consumer.h>
974f24d87SMarco Felsch #include <linux/module.h>
1074f24d87SMarco Felsch #include <sound/soc.h>
1174f24d87SMarco Felsch 
1274f24d87SMarco Felsch #define DRV_NAME "ssm2305"
1374f24d87SMarco Felsch 
1474f24d87SMarco Felsch struct ssm2305 {
1574f24d87SMarco Felsch 	/* shutdown gpio  */
1674f24d87SMarco Felsch 	struct gpio_desc *gpiod_shutdown;
1774f24d87SMarco Felsch };
1874f24d87SMarco Felsch 
ssm2305_power_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kctrl,int event)1974f24d87SMarco Felsch static int ssm2305_power_event(struct snd_soc_dapm_widget *w,
2074f24d87SMarco Felsch 			       struct snd_kcontrol *kctrl, int event)
2174f24d87SMarco Felsch {
2274f24d87SMarco Felsch 	struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
2374f24d87SMarco Felsch 	struct ssm2305 *data = snd_soc_component_get_drvdata(c);
2474f24d87SMarco Felsch 
2574f24d87SMarco Felsch 	gpiod_set_value_cansleep(data->gpiod_shutdown,
2674f24d87SMarco Felsch 				 SND_SOC_DAPM_EVENT_ON(event));
2774f24d87SMarco Felsch 
2874f24d87SMarco Felsch 	return 0;
2974f24d87SMarco Felsch }
3074f24d87SMarco Felsch 
3174f24d87SMarco Felsch static const struct snd_soc_dapm_widget ssm2305_dapm_widgets[] = {
3274f24d87SMarco Felsch 	/* Stereo input/output */
3374f24d87SMarco Felsch 	SND_SOC_DAPM_INPUT("L_IN"),
3474f24d87SMarco Felsch 	SND_SOC_DAPM_INPUT("R_IN"),
3574f24d87SMarco Felsch 	SND_SOC_DAPM_OUTPUT("L_OUT"),
3674f24d87SMarco Felsch 	SND_SOC_DAPM_OUTPUT("R_OUT"),
3774f24d87SMarco Felsch 
3874f24d87SMarco Felsch 	SND_SOC_DAPM_SUPPLY("Power", SND_SOC_NOPM, 0, 0, ssm2305_power_event,
3974f24d87SMarco Felsch 			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4074f24d87SMarco Felsch };
4174f24d87SMarco Felsch 
4274f24d87SMarco Felsch static const struct snd_soc_dapm_route ssm2305_dapm_routes[] = {
4374f24d87SMarco Felsch 	{ "L_OUT", NULL, "L_IN" },
4474f24d87SMarco Felsch 	{ "R_OUT", NULL, "R_IN" },
4574f24d87SMarco Felsch 	{ "L_IN", NULL, "Power" },
4674f24d87SMarco Felsch 	{ "R_IN", NULL, "Power" },
4774f24d87SMarco Felsch };
4874f24d87SMarco Felsch 
4974f24d87SMarco Felsch static const struct snd_soc_component_driver ssm2305_component_driver = {
5074f24d87SMarco Felsch 	.dapm_widgets		= ssm2305_dapm_widgets,
5174f24d87SMarco Felsch 	.num_dapm_widgets	= ARRAY_SIZE(ssm2305_dapm_widgets),
5274f24d87SMarco Felsch 	.dapm_routes		= ssm2305_dapm_routes,
5374f24d87SMarco Felsch 	.num_dapm_routes	= ARRAY_SIZE(ssm2305_dapm_routes),
5474f24d87SMarco Felsch };
5574f24d87SMarco Felsch 
ssm2305_probe(struct platform_device * pdev)5674f24d87SMarco Felsch static int ssm2305_probe(struct platform_device *pdev)
5774f24d87SMarco Felsch {
5874f24d87SMarco Felsch 	struct device *dev = &pdev->dev;
5974f24d87SMarco Felsch 	struct ssm2305 *priv;
6074f24d87SMarco Felsch 
6174f24d87SMarco Felsch 	/* Allocate the private data */
6274f24d87SMarco Felsch 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
6374f24d87SMarco Felsch 	if (!priv)
6474f24d87SMarco Felsch 		return -ENOMEM;
6574f24d87SMarco Felsch 
6674f24d87SMarco Felsch 	platform_set_drvdata(pdev, priv);
6774f24d87SMarco Felsch 
6874f24d87SMarco Felsch 	/* Get shutdown gpio */
6974f24d87SMarco Felsch 	priv->gpiod_shutdown = devm_gpiod_get(dev, "shutdown",
7074f24d87SMarco Felsch 					      GPIOD_OUT_LOW);
71*382ae995SKuninori Morimoto 	if (IS_ERR(priv->gpiod_shutdown))
72*382ae995SKuninori Morimoto 		return dev_err_probe(dev, PTR_ERR(priv->gpiod_shutdown),
73*382ae995SKuninori Morimoto 				     "Failed to get 'shutdown' gpio\n");
7474f24d87SMarco Felsch 
7574f24d87SMarco Felsch 	return devm_snd_soc_register_component(dev, &ssm2305_component_driver,
7674f24d87SMarco Felsch 					       NULL, 0);
7774f24d87SMarco Felsch }
7874f24d87SMarco Felsch 
7974f24d87SMarco Felsch #ifdef CONFIG_OF
8074f24d87SMarco Felsch static const struct of_device_id ssm2305_of_match[] = {
8174f24d87SMarco Felsch 	{ .compatible = "adi,ssm2305", },
8274f24d87SMarco Felsch 	{ }
8374f24d87SMarco Felsch };
8474f24d87SMarco Felsch MODULE_DEVICE_TABLE(of, ssm2305_of_match);
8574f24d87SMarco Felsch #endif
8674f24d87SMarco Felsch 
8774f24d87SMarco Felsch static struct platform_driver ssm2305_driver = {
8874f24d87SMarco Felsch 	.driver = {
8974f24d87SMarco Felsch 		.name = DRV_NAME,
9074f24d87SMarco Felsch 		.of_match_table = of_match_ptr(ssm2305_of_match),
9174f24d87SMarco Felsch 	},
9274f24d87SMarco Felsch 	.probe = ssm2305_probe,
9374f24d87SMarco Felsch };
9474f24d87SMarco Felsch 
9574f24d87SMarco Felsch module_platform_driver(ssm2305_driver);
9674f24d87SMarco Felsch 
9774f24d87SMarco Felsch MODULE_DESCRIPTION("ASoC SSM2305 amplifier driver");
9874f24d87SMarco Felsch MODULE_AUTHOR("Marco Felsch <m.felsch@pengutronix.de>");
9974f24d87SMarco Felsch MODULE_LICENSE("GPL v2");
100