xref: /linux/sound/soc/codecs/cs35l45-spi.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
1f9f46d05SCharles Keepax // SPDX-License-Identifier: GPL-2.0
20d463d01SJames Schulman //
30d463d01SJames Schulman // cs35l45-spi.c -- CS35L45 SPI driver
40d463d01SJames Schulman //
50d463d01SJames Schulman // Copyright 2019-2022 Cirrus Logic, Inc.
60d463d01SJames Schulman //
70d463d01SJames Schulman // Author: James Schulman <james.schulman@cirrus.com>
80d463d01SJames Schulman 
90d463d01SJames Schulman #include <linux/device.h>
100d463d01SJames Schulman #include <linux/module.h>
110d463d01SJames Schulman #include <linux/regmap.h>
120d463d01SJames Schulman #include <linux/spi/spi.h>
130d463d01SJames Schulman 
140d463d01SJames Schulman #include "cs35l45.h"
150d463d01SJames Schulman 
cs35l45_spi_probe(struct spi_device * spi)160d463d01SJames Schulman static int cs35l45_spi_probe(struct spi_device *spi)
170d463d01SJames Schulman {
180d463d01SJames Schulman 	struct cs35l45_private *cs35l45;
190d463d01SJames Schulman 	struct device *dev = &spi->dev;
200d463d01SJames Schulman 	int ret;
210d463d01SJames Schulman 
220d463d01SJames Schulman 	cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL);
230d463d01SJames Schulman 	if (cs35l45 == NULL)
240d463d01SJames Schulman 		return -ENOMEM;
250d463d01SJames Schulman 
2674b14e28SVlad.Karpovich 	spi->max_speed_hz = CS35L45_SPI_MAX_FREQ;
2774b14e28SVlad.Karpovich 	spi_setup(spi);
2874b14e28SVlad.Karpovich 
290d463d01SJames Schulman 	spi_set_drvdata(spi, cs35l45);
300d463d01SJames Schulman 	cs35l45->regmap = devm_regmap_init_spi(spi, &cs35l45_spi_regmap);
310d463d01SJames Schulman 	if (IS_ERR(cs35l45->regmap)) {
320d463d01SJames Schulman 		ret = PTR_ERR(cs35l45->regmap);
330d463d01SJames Schulman 		dev_err(dev, "Failed to allocate register map: %d\n", ret);
340d463d01SJames Schulman 		return ret;
350d463d01SJames Schulman 	}
360d463d01SJames Schulman 
370d463d01SJames Schulman 	cs35l45->dev = dev;
386085f9e6SVlad.Karpovich 	cs35l45->irq = spi->irq;
396c07be8fSVlad.Karpovich 	cs35l45->bus_type = CONTROL_BUS_SPI;
400d463d01SJames Schulman 
410d463d01SJames Schulman 	return cs35l45_probe(cs35l45);
420d463d01SJames Schulman }
430d463d01SJames Schulman 
cs35l45_spi_remove(struct spi_device * spi)440d463d01SJames Schulman static void cs35l45_spi_remove(struct spi_device *spi)
450d463d01SJames Schulman {
460d463d01SJames Schulman 	struct cs35l45_private *cs35l45 = spi_get_drvdata(spi);
470d463d01SJames Schulman 
480d463d01SJames Schulman 	cs35l45_remove(cs35l45);
490d463d01SJames Schulman }
500d463d01SJames Schulman 
510d463d01SJames Schulman static const struct of_device_id cs35l45_of_match[] = {
520d463d01SJames Schulman 	{ .compatible = "cirrus,cs35l45" },
530d463d01SJames Schulman 	{},
540d463d01SJames Schulman };
550d463d01SJames Schulman MODULE_DEVICE_TABLE(of, cs35l45_of_match);
560d463d01SJames Schulman 
570d463d01SJames Schulman static const struct spi_device_id cs35l45_id_spi[] = {
580d463d01SJames Schulman 	{ "cs35l45", 0 },
590d463d01SJames Schulman 	{}
600d463d01SJames Schulman };
610d463d01SJames Schulman MODULE_DEVICE_TABLE(spi, cs35l45_id_spi);
620d463d01SJames Schulman 
630d463d01SJames Schulman static struct spi_driver cs35l45_spi_driver = {
640d463d01SJames Schulman 	.driver = {
650d463d01SJames Schulman 		.name		= "cs35l45",
660d463d01SJames Schulman 		.of_match_table = cs35l45_of_match,
67*12e102b1SRicardo Rivera-Matos 		.pm		= pm_ptr(&cs35l45_pm_ops),
680d463d01SJames Schulman 	},
690d463d01SJames Schulman 	.id_table	= cs35l45_id_spi,
700d463d01SJames Schulman 	.probe		= cs35l45_spi_probe,
710d463d01SJames Schulman 	.remove		= cs35l45_spi_remove,
720d463d01SJames Schulman };
730d463d01SJames Schulman module_spi_driver(cs35l45_spi_driver);
740d463d01SJames Schulman 
750d463d01SJames Schulman MODULE_DESCRIPTION("SPI CS35L45 driver");
760d463d01SJames Schulman MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>");
77f9f46d05SCharles Keepax MODULE_LICENSE("GPL");
7831c90dd5SRichard Fitzgerald MODULE_IMPORT_NS(SND_SOC_CS35L45);
79