xref: /linux/sound/soc/codecs/cs35l56-spi.c (revision f9bff0e31881d03badf191d3b0005839391f5f2b)
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // CS35L56 ALSA SoC audio driver SPI binding
4 //
5 // Copyright (C) 2023 Cirrus Logic, Inc. and
6 //                    Cirrus Logic International Semiconductor Ltd.
7 
8 #include <linux/acpi.h>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/regmap.h>
12 #include <linux/spi/spi.h>
13 #include <linux/types.h>
14 
15 #include "cs35l56.h"
16 
17 static int cs35l56_spi_probe(struct spi_device *spi)
18 {
19 	const struct regmap_config *regmap_config = &cs35l56_regmap_spi;
20 	struct cs35l56_private *cs35l56;
21 	int ret;
22 
23 	cs35l56 = devm_kzalloc(&spi->dev, sizeof(struct cs35l56_private), GFP_KERNEL);
24 	if (!cs35l56)
25 		return -ENOMEM;
26 
27 	spi_set_drvdata(spi, cs35l56);
28 	cs35l56->regmap = devm_regmap_init_spi(spi, regmap_config);
29 	if (IS_ERR(cs35l56->regmap)) {
30 		ret = PTR_ERR(cs35l56->regmap);
31 		return dev_err_probe(&spi->dev, ret, "Failed to allocate register map\n");
32 	}
33 
34 	cs35l56->dev = &spi->dev;
35 
36 	ret = cs35l56_common_probe(cs35l56);
37 	if (ret != 0)
38 		return ret;
39 
40 	ret = cs35l56_init(cs35l56);
41 	if (ret == 0)
42 		ret = cs35l56_irq_request(cs35l56, spi->irq);
43 	if (ret < 0)
44 		cs35l56_remove(cs35l56);
45 
46 	return ret;
47 }
48 
49 static void cs35l56_spi_remove(struct spi_device *spi)
50 {
51 	struct cs35l56_private *cs35l56 = spi_get_drvdata(spi);
52 
53 	cs35l56_remove(cs35l56);
54 }
55 
56 static const struct spi_device_id cs35l56_id_spi[] = {
57 	{ "cs35l56", 0 },
58 	{}
59 };
60 MODULE_DEVICE_TABLE(spi, cs35l56_id_spi);
61 
62 static struct spi_driver cs35l56_spi_driver = {
63 	.driver = {
64 		.name		= "cs35l56",
65 		.pm = &cs35l56_pm_ops_i2c_spi,
66 	},
67 	.id_table	= cs35l56_id_spi,
68 	.probe		= cs35l56_spi_probe,
69 	.remove		= cs35l56_spi_remove,
70 };
71 
72 module_spi_driver(cs35l56_spi_driver);
73 
74 MODULE_DESCRIPTION("ASoC CS35L56 SPI driver");
75 MODULE_IMPORT_NS(SND_SOC_CS35L56_CORE);
76 MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
77 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
78 MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
79 MODULE_LICENSE("GPL");
80