xref: /openbmc/linux/sound/soc/codecs/cs35l45-spi.c (revision d47a97bd)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 //
3 // cs35l45-spi.c -- CS35L45 SPI driver
4 //
5 // Copyright 2019-2022 Cirrus Logic, Inc.
6 //
7 // Author: James Schulman <james.schulman@cirrus.com>
8 
9 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <linux/regmap.h>
12 #include <linux/spi/spi.h>
13 
14 #include "cs35l45.h"
15 
16 static int cs35l45_spi_probe(struct spi_device *spi)
17 {
18 	struct cs35l45_private *cs35l45;
19 	struct device *dev = &spi->dev;
20 	int ret;
21 
22 	cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL);
23 	if (cs35l45 == NULL)
24 		return -ENOMEM;
25 
26 	spi_set_drvdata(spi, cs35l45);
27 	cs35l45->regmap = devm_regmap_init_spi(spi, &cs35l45_spi_regmap);
28 	if (IS_ERR(cs35l45->regmap)) {
29 		ret = PTR_ERR(cs35l45->regmap);
30 		dev_err(dev, "Failed to allocate register map: %d\n", ret);
31 		return ret;
32 	}
33 
34 	cs35l45->dev = dev;
35 
36 	return cs35l45_probe(cs35l45);
37 }
38 
39 static void cs35l45_spi_remove(struct spi_device *spi)
40 {
41 	struct cs35l45_private *cs35l45 = spi_get_drvdata(spi);
42 
43 	cs35l45_remove(cs35l45);
44 }
45 
46 static const struct of_device_id cs35l45_of_match[] = {
47 	{ .compatible = "cirrus,cs35l45" },
48 	{},
49 };
50 MODULE_DEVICE_TABLE(of, cs35l45_of_match);
51 
52 static const struct spi_device_id cs35l45_id_spi[] = {
53 	{ "cs35l45", 0 },
54 	{}
55 };
56 MODULE_DEVICE_TABLE(spi, cs35l45_id_spi);
57 
58 static struct spi_driver cs35l45_spi_driver = {
59 	.driver = {
60 		.name		= "cs35l45",
61 		.of_match_table = cs35l45_of_match,
62 		.pm		= &cs35l45_pm_ops,
63 	},
64 	.id_table	= cs35l45_id_spi,
65 	.probe		= cs35l45_spi_probe,
66 	.remove		= cs35l45_spi_remove,
67 };
68 module_spi_driver(cs35l45_spi_driver);
69 
70 MODULE_DESCRIPTION("SPI CS35L45 driver");
71 MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>");
72 MODULE_LICENSE("Dual BSD/GPL");
73 MODULE_IMPORT_NS(SND_SOC_CS35L45);
74