xref: /linux/sound/pci/hda/cs35l56_hda_spi.c (revision 119ff04864a24470b1e531bb53e5c141aa8fefb0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // CS35L56 HDA audio driver SPI binding
4 //
5 // Copyright (C) 2023 Cirrus Logic, Inc. and
6 //                    Cirrus Logic International Semiconductor Ltd.
7 
8 #include <linux/module.h>
9 #include <linux/regmap.h>
10 #include <linux/spi/spi.h>
11 
12 #include "cs35l56_hda.h"
13 
14 static int cs35l56_hda_spi_probe(struct spi_device *spi)
15 {
16 	struct cs35l56_hda *cs35l56;
17 	int ret;
18 
19 	cs35l56 = devm_kzalloc(&spi->dev, sizeof(*cs35l56), GFP_KERNEL);
20 	if (!cs35l56)
21 		return -ENOMEM;
22 
23 	cs35l56->base.dev = &spi->dev;
24 
25 #ifdef CS35L56_WAKE_HOLD_TIME_US
26 	cs35l56->base.can_hibernate = true;
27 #endif
28 	cs35l56->base.regmap = devm_regmap_init_spi(spi, &cs35l56_regmap_spi);
29 	if (IS_ERR(cs35l56->base.regmap)) {
30 		ret = PTR_ERR(cs35l56->base.regmap);
31 		dev_err(cs35l56->base.dev, "Failed to allocate register map: %d\n",
32 			ret);
33 		return ret;
34 	}
35 
36 	ret = cs35l56_hda_common_probe(cs35l56, spi_get_chipselect(spi, 0));
37 	if (ret)
38 		return ret;
39 	ret = cs35l56_irq_request(&cs35l56->base, spi->irq);
40 	if (ret < 0)
41 		cs35l56_hda_remove(cs35l56->base.dev);
42 
43 	return ret;
44 }
45 
46 static void cs35l56_hda_spi_remove(struct spi_device *spi)
47 {
48 	cs35l56_hda_remove(&spi->dev);
49 }
50 
51 static const struct spi_device_id cs35l56_hda_spi_id[] = {
52 	{ "cs35l56-hda", 0 },
53 	{}
54 };
55 
56 static struct spi_driver cs35l56_hda_spi_driver = {
57 	.driver = {
58 		.name		= "cs35l56-hda",
59 		.pm		= &cs35l56_hda_pm_ops,
60 	},
61 	.id_table	= cs35l56_hda_spi_id,
62 	.probe		= cs35l56_hda_spi_probe,
63 	.remove		= cs35l56_hda_spi_remove,
64 };
65 module_spi_driver(cs35l56_hda_spi_driver);
66 
67 MODULE_DESCRIPTION("HDA CS35L56 SPI driver");
68 MODULE_IMPORT_NS(SND_HDA_SCODEC_CS35L56);
69 MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
70 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
71 MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
72 MODULE_LICENSE("GPL");
73