1 // SPDX-License-Identifier: GPL-2.0
3 // cs35l41-spi.c -- CS35l41 SPI driver
5 // Copyright 2017-2021 Cirrus Logic, Inc.
7 // Author: David Rhodes <david.rhodes@cirrus.com>
9 #include <linux/acpi.h>
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/platform_device.h>
16 #include <linux/spi/spi.h>
18 #include <sound/cs35l41.h>
21 static const struct spi_device_id cs35l41_id_spi[] = {
27 MODULE_DEVICE_TABLE(spi, cs35l41_id_spi);
29 static int cs35l41_spi_probe(struct spi_device *spi)
31 const struct regmap_config *regmap_config = &cs35l41_regmap_spi;
32 struct cs35l41_platform_data *pdata = dev_get_platdata(&spi->dev);
33 struct cs35l41_private *cs35l41;
36 cs35l41 = devm_kzalloc(&spi->dev, sizeof(struct cs35l41_private), GFP_KERNEL);
40 spi->max_speed_hz = CS35L41_SPI_MAX_FREQ;
43 spi_set_drvdata(spi, cs35l41);
44 cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config);
45 if (IS_ERR(cs35l41->regmap)) {
46 ret = PTR_ERR(cs35l41->regmap);
47 dev_err(&spi->dev, "Failed to allocate register map: %d\n", ret);
51 cs35l41->dev = &spi->dev;
52 cs35l41->irq = spi->irq;
54 return cs35l41_probe(cs35l41, pdata);
57 static int cs35l41_spi_remove(struct spi_device *spi)
59 struct cs35l41_private *cs35l41 = spi_get_drvdata(spi);
61 cs35l41_remove(cs35l41);
67 static const struct of_device_id cs35l41_of_match[] = {
68 { .compatible = "cirrus,cs35l40" },
69 { .compatible = "cirrus,cs35l41" },
72 MODULE_DEVICE_TABLE(of, cs35l41_of_match);
76 static const struct acpi_device_id cs35l41_acpi_match[] = {
77 { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
80 MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
83 static struct spi_driver cs35l41_spi_driver = {
86 .of_match_table = of_match_ptr(cs35l41_of_match),
87 .acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
89 .id_table = cs35l41_id_spi,
90 .probe = cs35l41_spi_probe,
91 .remove = cs35l41_spi_remove,
94 module_spi_driver(cs35l41_spi_driver);
96 MODULE_DESCRIPTION("SPI CS35L41 driver");
97 MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
98 MODULE_LICENSE("GPL");